Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken style to script conversion when there is comment before document block after global part #1245

Closed
myfonj opened this issue Feb 9, 2024 · 2 comments

Comments

@myfonj
Copy link

myfonj commented Feb 9, 2024

The global part seems to be completely omitted from JS version of userstyle when there is a comment before @-moz-document block at the end of the "global" part.

Test: https://greasyfork.org/en/scripts/486968-test-style-for-debugging-conversion-to-userscript/code?version=1325339

https://update.greasyfork.org/scripts/486968/1325339/Test%20style%20for%20debugging%20conversion%20to%20userscript.user.css :

...

/**/
el { color: green; }

/**/
@-moz-document domain("facebook.com") { el { color: red; } }

produces https://update.greasyfork.org/scripts/486968/1325339/Test%20style%20for%20debugging%20conversion%20to%20userscript.user.js :

...
// @include http://facebook.com/*
// @include https://facebook.com/*
// @include http://*.facebook.com/*
// @include https://*.facebook.com/*
// @downloadURL none
// ==/UserScript==

(function() {
let css = ` el { color: red; } `;
...

NB there is no el { color: green; } whatsoever.

While https://greasyfork.org/en/scripts/486968-test-style-for-debugging-conversion-to-userscript/code?version=1325324

https://update.greasyfork.org/scripts/486968/1325324/Test%20style%20for%20debugging%20conversion%20to%20userscript.user.css

...

/**/
el { color: green; }

@-moz-document domain("facebook.com") { /**/ el { color: red; } }

produces

...
// @include *
// @downloadURL none
// ==/UserScript==

(function() {
let css = "";
css += `

/**/

el { color: green; }

`;
if ((location.hostname === "facebook.com" || location.hostname.endsWith(".facebook.com"))) {
  css += ` /**/ el { color: red; } `;
}
...

What is OK.

Got couple of bugreports for https://greasyfork.org/en/scripts/408378-unround-everything-everywhere/feedback when hit this problem.

@JasonBarnabe
Copy link
Collaborator

Thanks for the minimal reproduction case. It appears as though it thinks the the portion outside of the @-moz-document consists entirely of comments. This is because it starts with /* and ends with */ (ignoring whitespace). The CSS parser is not very sophisticated in this way, but I think I can fix this case.

@JasonBarnabe
Copy link
Collaborator

I've put in a fix; let me know if this is still an issue.

Note the contents of version-specific code URLs are cached for 24 hours, so https://update.greasyfork.org/scripts/486968/1325339/Test%20style%20for%20debugging%20conversion%20to%20userscript.user.js may not show the fix until tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants