Này người xa lạ!

Còn chờ gì nữa mà không mau đăng nhập hoặc đăng ký để cùng tham gia thảo luận với cộng đồng!

HELP - How to Use GM_addStyle and //@resource with Chrome ??

đã sửa December 2018 trong Phát triển Firefox

I wrote an userscript to use my userstyles in a GM directly:
Userstyles / GreasyFork Enhancer Dark-Grey + Comments Numbering
It used before this library:
But it seems not working.

After reading:
How do I use CSS with Greasemonkey? ,
i fix it by using now GM_addStyle and //@resource.
It seems more simple for me.

It work, but only in Firefox.
How can i write it to adapt it for Chrome too ?

I use 2 //@resource:
Maybe it's the problem?
I am not sure if it is the good way to write it.

Here my script:
// ==UserScript==
// @name Userstyles / GreasyFork Enhancer Dark-Grey + Comments Numbering v.122
// @namespace http://userscripts.org/users/5161
// @icon http://www.gravatar.com/avatar/317bafeeda69d359e34f813aff940944?r=PG&s=48&default=identicon
// @description Custom Widescreen CSS theme for userstyles.org and https://greasyfork.org
// @copyright 2011+, decembre (http://userscripts.org/users/5161)
// @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @version 122

// @include      https://userstyles.org/*
// @include      https://greasyfork.org/*
// @include      https://sleazyfork.org/*   

// CSS1 = Userstyles - Greasy Fork Enhancer Dark-Grey  v.121
// @resource      CSS1 https://pastebin.com/raw/f77ygmrt

// CSS2 = Userstyles - GreasyFork - Forum - Comments Numbering + Permalink v.115
// @resource      CSS2 https://pastebin.com/raw/D7XrTyQj

// @grant         GM_addStyle

// @grant         GM_getResourceText
// ==/UserScript==


Bình luận

  • Chrome doesn't support @-moz-document sections which is a nonstandard Firefox-only feature, which is why it ignores everything inside such sections. You have two options if you don't want to use an extension such as Stylus in Chrome: 1) implement URL handling yourself, parse, and apply sections dynamically on URL change, or 2) simply put everything in a plain CSS without sections and risk some CSS being applied incorrectly.

  • đã sửa December 2018 Firefox

    Thanks for your fast reply!
    Have you some related pages or scripts example for a newbie like me ;-)

    2) simply put everything in a plain CSS without sections and risk some CSS being applied incorrectly_:
    Because it don't take care of the different namespace ?

    I have seen , but not tested, the possibility to insert a stylesheet into the header of the pages:
    It's a solution for this script and what's happens for namespaces?

    I tested too the install userstyles by script in the site Userstyles.org and i see it does the job perfectly .

    • How it execute that?
    • It's possible to use its function for external Userstyles (like mine on Pastebin) ?
  • Namespace is not needed in Chrome in 99.9999999999% of cases.

    As for userstyles.org code, it does what I said above - it checks the URLs manually so yeah, you can do the same. Just find a multisection style and see how it looks as a userscript, then adapt to your code. One note though: their code is executed internally on all sites, which slows down the browser, so you need to keep your // @include entries.

  • "Just find a multisection style":
    Like this one ?
    After the transform to an userscript by the userstyles site,
    it seems working fine.

    The problem:
    I can't see the script which does this job internally in Userstyles.org.
    I find the code repository:
    Online repository of user styles. http://userstyles.org
    but not something i can adapt (i am not coder).


Đăng nhập hoặc Đăng ký để gửi bình luận.