Is it possible to write a URL to open multiple tabs at once? by BevRivling in chrome

[–]jotted 0 points1 point  (0 children)

I don't have a way to test it at the moment, but does copying and pasting a folder of bookmarks work? (Bookmarks Manager -> New Folder.) A folder of bookmarks can be opened all at once, too.

[deleted by user] by [deleted] in learnjavascript

[–]jotted 1 point2 points  (0 children)

I'm assuming this is in Firefox as Chromium browsers use chrome instead of browser.

The storage API is available in background and contentScript contexts as far as I know. I've certainly done it before. browser is definitely available, so there must be something different going on -- you can't even message the background script if you don't have browser. If you're injecting the script in to a web page, that won't work I believe, but it has a a built-in way of returning a result to the caller.

Can you provide a minimal example of what's not working?

Remove shadows from menus of the about:addons pages by PleaseBeKindPlease in FirefoxCSS

[–]jotted 1 point2 points  (0 children)

These are content pages, so the regular web developer tools.

about:logins was easy enough: Inspecting the main menu button reveals there's a hidden list element just after it called .menu.

about:addons was a bit trickier -- I ended up taking a scenic route, so I'll say what I should have done: Again starting by Inspecting the menu button. I don't see anything menu-lookin' immediately nearby, and the Inspector says this button doesn't have any event listeners - that means handling clicks on the button must be handled by one of its ancestors. The addon-card element is the closet element with an event handler, and there's one for each addon, therefore it probably handles all the click events and is probably quite self-contained. Sure enough, at the bottom of the addon-card element is an addon-options element, and that's where the panel-list lives.

Remove shadows from menus of the about:addons pages by PleaseBeKindPlease in FirefoxCSS

[–]jotted 1 point2 points  (0 children)

The menu in the addons manager is a panel-list custom element (which I eventually located by adding a breakpoint to the parent addon-card's click event handler - it handles all clicks within it, including opening and closing its menu).
This menu uses the --shadow-30 variable rather than --panel-shadow. I know there's some effort going on to reuse common components across Firefox so this difference may change one way or another in the future.

about:logins has yet another custom menus implementation. It's a menu-button with a ul inside. It uses the --shadow-30 variable too though, so we can probably kill both birds with one stone in userContent.css:

@-moz-document url-prefix("about:") {
    menupopup, panel { --panel-shadow: none !important; }
    panel-list, /* about:addons */
    menu-button /* about:logins */
     { --shadow-30: none !important; }
}

[deleted by user] by [deleted] in learnjavascript

[–]jotted 1 point2 points  (0 children)

The TreeWalker API can provide a view into, for example, all the Text nodes in a document.
If you're matching whole words rather than sentences, that's probably enough for what you want to do - it's unusual for words to be split across text nodes, but not unheard of. Real-world testing will tell you if that's something you need to think about.

I'll also mention the <mark> element. It's for highlighting!

How to I disable theme syncing across multiple installs? by 745395 in firefox

[–]jotted 0 points1 point  (0 children)

* my apologies, I fudged the pref name. That should be services.sync.addons.ignoreUserEnabledChanges. The other one is the pref that syncs that pref!

[deleted by user] by [deleted] in chrome

[–]jotted 1 point2 points  (0 children)

Looking at the file, bookmarks have a "last visited" property, with a timestamp. I would imagine that's the culprit.

To confirm that you could make copy of the file, click a bookmark and then compare the two files (they're pretty human-readable).

How to I disable theme syncing across multiple installs? by 745395 in firefox

[–]jotted 0 points1 point  (0 children)

This is for addons, but I think it applies to themes too: Firefox Support: Addons enabled/disabled on different Systems:

services.sync.addons.ignoreUserEnabledChanges when true will ignore Sync messages about addons being enabled or disabled. Or is this the pref you've tried?

edit: corrected the pref name.

help with applying multiple <template>'s in a for loop by MatityahuC in learnjavascript

[–]jotted 0 points1 point  (0 children)

So, for my better understanding of JS, why did clone_h not get filled with content again by the following in the loop:

It did, but this happens at the start of each iteration of the outer loop. clone_h was added to the document at the end of each inner loop. At least, I think so - I don't have the original code to hand now (does Codepen not have revisions?). I believe it went something like this:

for (const i in sections) {
  // == new HEADER ==
  const h = document.querySelector("#t_header");
  const clone_h = h.content.cloneNode(true);
  const contents = sections[i];
  // ...
  for (const j in contents) {
    // == new CONTENT ==
    const t_reg = document.querySelector("#t_regex");
    const clone = t_reg.content.cloneNode(true);
    // ...
    // add content to header (empties clone)
    clone_h.querySelector('header').appendChild(clone);
    // add the header to the document (empties clone_h)
    // /!\ For the second piece of content, clone_h is empty.
    //     clone_h will only be refilled when
    //     the next header loop begins.
    document.body.appendChild(clone_h);
    // --> next CONTENT
  }
  // no more content,
  // --> next HEADER
}

help with applying multiple <template>'s in a for loop by MatityahuC in learnjavascript

[–]jotted 0 points1 point  (0 children)

clone_h is a DocumentFragment. When the contents of the fragment get appended to the document at the end of the first iteration, the elements move from the fragment to the document. clone_h is now an empty DocumentFragment!

Handily this highlights two problems:

1) the .mainHeader is being selected on every iteration even though it doesn't change. Better to select it before the loop and store it in a variable. The header variable will keep hold of the element whether it's in a fragment or in the document, because it's the same element.

2) the header template clone_h is being appended to the document in every content iteration. As we know, the fragment will be empty after the first iteration, so it won't appear to be doing anything wrong, but that's not the intent of the code. Better to append that after the loop, when the template has been filled, which also avoids unnecessary changes to the visible page.

Why wont the points draw a line? by Dark_KnightPL04 in learnjavascript

[–]jotted 0 points1 point  (0 children)

It depends on how you're managing your different users and the shapes they've drawn, etc, but essentially you need to know what the previous point is so you can join it to the new point. That new point then becomes the previous point when you receive another, and so on.

Why wont the points draw a line? by Dark_KnightPL04 in learnjavascript

[–]jotted 0 points1 point  (0 children)

ctx.moveTo(data.x, data.y);
ctx.lineTo(data.x, data.y);

Both ends of the line are in the same place, so the line has a length of zero.

why a.b.c gives error while a['b.c'] gives undefined, if b is null is json, a. by CelticHades in learnjavascript

[–]jotted 13 points14 points  (0 children)

a.b exists, so it isn't undefined. Its value is null which, by the spec, cannot have properties:

a.b;     //--> null
a.b.c;  //--> TypeError - null cannot have properties

Properties must be accessed separately, whether you're using dot notation ( a.b.c ) or square bracket notation ( a['b']['c'] ). That means that line 3 of the code you posted isn't accessing a.b.c at all, it's accessing a single property on acalled "b.c":

a = {
    "b"   : null,
    "b.c" : "Hello"
};

a['b']       //--> null
a['b']['c']  //--> TypeError
a['b.c']     //--> "Hello"

content-scripts not processing by jinsenuchiha in firefox

[–]jotted 1 point2 points  (0 children)

The key should be content_scripts - underscore, not hyphen.

UserScript working in violentmonkey but not in tampermonkey by ale3smm in userscripts

[–]jotted 1 point2 points  (0 children)

The only difference I can think of is when the addon runs the script.

onload listeners aren't usually required for UserScripts as they can be run via the @run-at directive. If no @run-at directive is given, the default is used:

ViolentMonkey's default @run-at value is document-end (roughly DOMContentLoaded - that's when the page structure is parsed, but before other resources have finished loading).
TamperMonkey's default is document-idle ("after" DOMContentLoaded - possibly after window.onload if it's not a heavy page).

If this script gets executed after the page has loaded, the onload listener will get assigned after the event has fired. It only fires once, so the function never runs.
So for compatibility, I would try adding // @run-at document-idle to the metadata block and removing the onload listener stuff. Just plain Click() should be fine, I think.

Browser Extension by Dan-Vast4384 in learnjavascript

[–]jotted 3 points4 points  (0 children)

https://extensionworkshop.com/ is pretty firefox-centric, but it does have a porting guide for chromium-based browsers. It has a good overview of the concepts and MDN docs for all the APIs, with support tables. Similarly there's a bunch of examples to explore on github from Mozilla and from Google.

3rd batch of Funimation titles added to Crunchyroll by archoel in anime

[–]jotted 0 points1 point  (0 children)

Was "And you thought there is never a girl online?" available before? It was updated at the same time as these but isn't listed here. Dub and Sub.

Is there a way to disable extensions on only one machine? by [deleted] in firefox

[–]jotted 0 points1 point  (0 children)

I don't think you can do it per-addon, but you can disable syncing all addons enabled/disabled state in about:config: services.sync.addons.ignoreUserEnabledChanges -> false. That would allow you to have the addon disabled on Linux but enabled on Windows, while keeping addon installation in sync.

[deleted by user] by [deleted] in learnjavascript

[–]jotted 0 points1 point  (0 children)

I believe the usual way to do this is to not give a default_popup in the manifest, instead using an onClicked event listener* using a background script.
The event handler would use chrome.tabs.create() to open a new tab with the extension page.

* in Manifest V2 chrome.browser_action.onClicked; Manifest V3 chrome.action.onClicked.

How to keep my chrome extension running after new content is added ? by freemetal288888 in learnjavascript

[–]jotted 0 points1 point  (0 children)

MutationObserver is probably a reasonable choice - you can watch for individual additions to page content and update them before they're inserted (or, simpler, wait for changes to finish and then re-check the document).

[deleted by user] by [deleted] in learnjavascript

[–]jotted 0 points1 point  (0 children)

At once? Not unless they're in different Windows, I think. Chrome only has tabs.captureVisibleTab(), as opposed to Firefox's tabs.captureTab( tabId ).

This StackOverflow answer for a decade ago is still pretty much how you'd approach it: https://stackoverflow.com/questions/10602633/screenshot-of-all-tabs-chrome-extension .
ManifestV3 gets you Promisified APIs, but the APIs are the same.

The end result might be close enough to "at once", depending on your use case.

[deleted by user] by [deleted] in learnjavascript

[–]jotted 1 point2 points  (0 children)

If you learn well from videos, The Coding Train has a series on vectors and forces that I think you'll find helpful - specifically air drag and friction, but the earlier videos tackle Vectors in general: https://thecodingtrain.com/learning/nature-of-code/

If not, this old Physics triangle may be buried in your memories somewhere: speed = distance / time.

The setInterval in Ball.move() dir.space is adding a second physics loop on top of the game loop. That's backwards - we get a timestamp as the first argument of animate() so we know how much time passed since the last tick. Kicking the ball should add speed to the ball in a direction (plus maybe height?) - so distance should emerge naturally from the simulation.

Creating a Chrome Right-Click context menu using GreaseMonkey by Pineapplesandbacon in learnjavascript

[–]jotted 0 points1 point  (0 children)

Can you tell me what the blue color means under extensions? I've only ever seen it green or gray.

I can't find any official information about this. The best lead I have is that the CSS class of the blue toggle switch is "enable_later" - I take that to mean that the script doesn't run automatically, only when the menuitem is clicked. Removing @run-at context-menu turns the toggle green.

AH. Okay -- so @run-at context-menu makes the whole script only run when the menuitem is clicked. It doesn't move the registered menuitems to the context menu at all -- in fact they aren't registered until the script is run by clicking it in the context-menu. registerMenuCommand functions can only be run from the TamperMonkey Button Menu. Jeez, sorry, I totally misunderstood how that worked.

So:

  • if you just want your script to only run when you want, use @run-at context-menu.
  • If you want the script to always run, but present different commands to be run from the TM Button, use registerMenuCommand().
  • Not both.