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

[FireMonkey] 4chan-x help? #507

Closed
ghost opened this issue Sep 26, 2022 · 22 comments
Closed

[FireMonkey] 4chan-x help? #507

ghost opened this issue Sep 26, 2022 · 22 comments
Labels
addon: FireMonkey userscript: compatibility userScript/userCSS Compatibility

Comments

@ghost
Copy link

ghost commented Sep 26, 2022

Hello, apologies if this is the wrong place to post this.

I'm no expert in programming/userscript writing so a lot of the "Help" page is overly-technical jargon.

I am having trouble getting 4chan X to work with Firefox and the latest version of FireMonkey. My 4chan X settings are not being saved upon reopening 4chan(nel). I saw issue #408 and read through it, but don't see @grant or @disable-synchGM under User Metadata.

additionally, how would I get this script to run automatically rather than needing to manually go in and click "run" each time the page loads?

thanks for any help.

@erosman
Copy link
Owner

erosman commented Sep 27, 2022

Hello, apologies if this is the wrong place to post this.

Hi. This is the right place. You can also post to #429

I saw issue #408 and read through it, but don't see @grant or @disable-synchGM under User Metadata.

@disable-synchGM was later removed in v2.42 as its function was automatically applied.

how would I get this script to run automatically rather than needing to manually go in and click "run" each time the page loads?

If a userscript is enabled it should run every time you go to the page.
The RUN function is for running a userscript that is not enabled, or to re-run it.

Let me ask other users and see if they are having issues with it.

@ghost
Copy link
Author

ghost commented Sep 27, 2022

I see. The script does not run automatically for me (despite it saying "enabled" in Scripts & CSS > [JS] 4chan X). I did not do any configuration other than installing FM and the script.

@erosman
Copy link
Owner

erosman commented Sep 27, 2022

Try this.....

  • Go to https://www.4chan.org/
  • FireMonkey should show that the userscript is active
    image
  • Open Developer tool (F12)
  • Go to Debugger Tab
  • If you don't see user-script:// refresh the page (F5)
  • You should see something like this
    image

Above shows that script is injected.

If the userscript does not seem to run.

Actually, I found an error .... in Browser Console.

image

I have posted Update API type verification in userscript.

@erosman
Copy link
Owner

erosman commented Sep 27, 2022

For the time being, try removing these line from the userscript and see:

Test 1:
Remove line 99:

// @grant        GM_addValueChangeListener

Test 2:
Remove lines 102-107 (keep line 99)

// @grant        GM.getValue
// @grant        GM.setValue
// @grant        GM.deleteValue
// @grant        GM.listValues
// @grant        GM.openInTab
// @grant        GM.xmlHttpRequest

@g-2-s
Copy link

g-2-s commented Sep 27, 2022

Test 2: Remove lines 102-107 (keep line 99)

// @grant        GM.getValue
// @grant        GM.setValue
// @grant        GM.deleteValue
// @grant        GM.listValues
// @grant        GM.openInTab
// @grant        GM.xmlHttpRequest

Doing this seems to make the script work.

@erosman
Copy link
Owner

erosman commented Sep 27, 2022

Test 3:

Change line 5549 (keep metadata block as original)

if (typeof GM_setValue !== "undefined" && typeof GM_addValueChangeListener !== "undefined" && GM_addValueChangeListener !== null) {
  $.setValue = GM_setValue;
  $.deleteValue = GM_deleteValue;
} 

@g-2-s
Copy link

g-2-s commented Sep 27, 2022

Test 3:

Change line 5549 (keep metadata block as original)

if (typeof GM_setValue !== "undefined" && typeof GM_addValueChangeListener !== "undefined" && GM_addValueChangeListener !== null) {
  $.setValue = GM_setValue;
  $.deleteValue = GM_deleteValue;
} 

This works great and it feels like the userscript runs better than the Test 2 solution.
Only "drawback" with this solution is that if you nuke/sanitize your Firefox data on close the userscript doesn't remember your settings and you have to import or set them again. Also this differentiates between 4chan and 4channel so when importing your settings file, you have to do it on both sites.
Thanks erosman by the way!

@erosman
Copy link
Owner

erosman commented Sep 27, 2022

I have posted Update API type verification in userscript.

Hopefully they will update the script.

I remember we had a mod script in YaBB & phpBB long time. I might be able to create a process to make changes to the script but that is fair amount of work and depends on how popular the feature would be.

There is also MV3 (manifest v3) coming up which will change the way userscripting work. The code might have to be altered for MV3.

@ghost
Copy link
Author

ghost commented Sep 27, 2022

I apologize for the delayed response.

I did the changes you suggested in Test 2. I am not doing Test 3's changes, as I reset FF's data upon restart which would facilitate my settings-being-reset issue.

The script now runs automatically and remembers settings through restarts. Thank you so much, you have been more than helpful and incredibly punctual.

@tomato-paste
Copy link

Test 2:
Remove lines 102-107 (keep line 99)

I had to do this to make the script work.

If GM_* works just fine, wouldn't prioritising GM_* in 4chan X code make it work? FM disables GM_* when GM.* is supported, so I can't try it out.

@erosman
Copy link
Owner

erosman commented Jan 7, 2024

The main issue of the old (pre-Firefox 57) GM3 type API is the sync storage API .e.g. GM_getValue, GM_setValue, GM_deleteValue, GM_listValues.

Strangely, the script uses GM_addValueChangeListener as a test for the above.

    if (typeof GM_addValueChangeListener !== "undefined" && GM_addValueChangeListener !== null) {
      $.setValue = GM_setValue;
      $.deleteValue = GM_deleteValue;
    }

If GM_* works just fine, wouldn't prioritising GM_* in 4chan X code make it work? FM disables GM_* when GM.* is supported, so I can't try it out.

GM_* is supported but the support has drawbacks and it is not 100%.
On the other hand, GM.* is fully supported.

FM disables GM_* when GM.* is supported, so I can't try it out.

You can test by removing GM.* from the metadata block.

@tomato-paste
Copy link

tomato-paste commented Jan 7, 2024

The main issue of the old (pre-Firefox 57) GM3 type API is the sync storage API .e.g. GM_getValue, GM_setValue, GM_deleteValue, GM_listValues.

Actually, I don't think the code should resort to those in the first place. L5433:
if (((typeof GM !== "undefined" && GM !== null ? GM.deleteValue : void 0) !== null) && window.BroadcastChannel && (typeof GM_addValueChangeListener === "undefined" || GM_addValueChangeListener === null)) {
The code attempts to use the GM.* API first. Do you have any idea what is window.BroadcastChannel? It probably checks for support of the Broadcast Channel API, but I don't know if that is the correct way.

Also, the FM editor says that the BroadcastChannel() constructor is undefined. (I'm not on an old FF version.)

@erosman
Copy link
Owner

erosman commented Jan 7, 2024

Do you have any idea what is window.BroadcastChannel?

Sorry, I don't. It might be something that is defined in the webpage.

Also, the FM editor says that the BroadcastChannel() constructor is undefined. (I'm not on an old FF version.)

My guess is that it is related to the webpage.

GM|TM|CM use content context which has the same window as the webpage, while FM uses the isolated userScript context.

You can try:

window.BroadcastChannel = unsafeWindow.BroadcastChannel;

@tomato-paste
Copy link

I also forgot to mention, the actual code uses != for comparison. I changed that to !==, didn't fix it.

Do you have any idea what is window.BroadcastChannel?

Sorry, I don't. It might be something that is defined in the webpage.

Also, the FM editor says that the BroadcastChannel() constructor is undefined. (I'm not on an old FF version.)

My guess is that it is related to the webpage.

GM|TM|CM use content context which has the same window as the webpage, while FM uses the isolated userScript context.

You can try:

window.BroadcastChannel = unsafeWindow.BroadcastChannel;

That didn't work. The Mozilla page says that this API is for workers, I don't know what that is.

@erosman
Copy link
Owner

erosman commented Jan 7, 2024

TBH, it is way too large to try and debug. The userscript developer is more familiar with the userscript code.

@tomato-paste
Copy link

TBH, it is way too large to try and debug. The userscript developer is more familiar with the userscript code.

Thanks, I'll try asking in the 4chan X issue tracker tommorow.

@tomato-paste
Copy link

tomato-paste commented Jan 10, 2024

I figured it out. Although FM disables GM_*, it keeps GM_addValueChangeListener enabled. The code prefers using GM_addValueChangeListener when it's enabled, so it fallbacks to GM_*. (details: ccd0/4chan-x#1534 Tampermonkey/tampermonkey#459)

if (((typeof GM !== "undefined" && GM !== null ? GM.deleteValue : void 0) !== null) && window.BroadcastChannel) { works.
But it is extremely slow, it takes around 5-10 seconds for the script to load when it should be instant.

What would be the best solution for this?

@erosman
Copy link
Owner

erosman commented Jan 10, 2024

Although FM disables GM_*, it keeps GM_addValueChangeListener enabled.

The reason is that the main difference is in the storage API and there is no difference between GM_addValueChangeListener & GM.addValueChangeListener.

As I mentioned earlier: "Strangely, the script uses GM_addValueChangeListener as a test for the above."

But it is extremely slow, it takes around 5-10 seconds for the script to load when it should be instant.

The change of the argument in the conditional makes no difference in execution speed. The result of the conditional however, depends on how the code handles it.

new BroadcastChannel() might not work in userScripts context.
You can try the following and see if that helps.

$.syncChannel = new window.BroadcastChannel(g.NAMESPACE + 'sync');

or...

$.syncChannel = new unsafeWindow.BroadcastChannel(g.NAMESPACE + 'sync');

@tomato-paste
Copy link

The reason is that the main difference is in the storage API and there is no difference between GM_addValueChangeListener & GM.addValueChangeListener.

As I mentioned earlier: "Strangely, the script uses GM_addValueChangeListener as a test for the above."

The code resorts to using Broadcast Channel when GM.* is supported but GM_addValueChangeListener isn't supported. The code assumes GM_* is supported when GM_addValueChangeListener is supported.

I assume this is because GreaseMonkey removed addValueChangeListener, so Broadcast Channel is used as a substitute. Reference: ccd0/4chan-x@8bc6fe1

The change of the argument in the conditional makes no difference in execution speed. The result of the conditional however, depends on how the code handles it.

I know, I meant that the GM.* code was really slow.

new BroadcastChannel() might not work in userScripts context. You can try the following and see if that helps.

I don't see any errors about BroadcastChannel being undefined in Ctrl+Shift+J, and adding window. or unsafeWindow. doesn't make a difference.

@erosman
Copy link
Owner

erosman commented Jan 10, 2024

I meant that the GM.* code was really slow.

It is true that the GM_* storage API is async and slower than the sync GM_* storage API, however the difference should in milliseconds.

(async() => {
  let t;
  const n = 10;

  t = performance.now();
  for (let i = 0; i < n; i++) {
    await browser.storage.local.get('_0 API');
  }
  console.log(`Operation took ${performance.now() - t} milliseconds`); // 4 millisecond
})();

It uses a loop to get/set values and I don't know how many get/set are done in that loop.
FireMonkey supports multiple get/set but other userscript managers don't.

Did you try removing the GM_* from the metadata block to force the sync GM_*?

@tomato-paste
Copy link

Did you try removing the GM_* from the metadata block to force the sync GM_*?

Yes, the script runs completely fine when I do that.

@erosman
Copy link
Owner

erosman commented Jan 10, 2024

Yes, the script runs completely fine when I do that.

Then, I guess that way would be best for the time being.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addon: FireMonkey userscript: compatibility userScript/userCSS Compatibility
Projects
None yet
Development

No branches or pull requests

3 participants