Add USw hook to remove get stylus button
This patch add an hook into the https://userstyles.world/style/* pages to watch for the Get Stylus button and removes it. As user's who already have stylus installed don't need to see this again.
This commit is contained in:
parent
d736a00bc1
commit
47c2576258
41
content/install-hook-userstylesworld.js
Normal file
41
content/install-hook-userstylesworld.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/* global API */// msg.js
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
(() => {
|
||||||
|
function watchForStylusButton() {
|
||||||
|
// Use 1 function so we won't have duplicate code around.
|
||||||
|
const stylusQuery = () => document.querySelector("a#stylus");
|
||||||
|
|
||||||
|
if (!stylusQuery()) {
|
||||||
|
const stylusButtonObserver = new MutationObserver(() => {
|
||||||
|
if (stylusQuery()) {
|
||||||
|
stylusButtonObserver.disconnect();
|
||||||
|
stylusQuery().remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
stylusButtonObserver.observe(document.body, {childList: true, subtree: true});
|
||||||
|
} else {
|
||||||
|
stylusQuery().remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some trickery to make sure that the DOM is ready(document.body/document.head).
|
||||||
|
// And can possibly observe it for a stylus button.
|
||||||
|
|
||||||
|
function isDOMReady() {
|
||||||
|
return document.readyState === 'complete' || document.readyState === 'interactive';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isDOMReady()) {
|
||||||
|
const onReadyStateChange = () => {
|
||||||
|
if (isDOMReady()) {
|
||||||
|
document.removeEventListener('readystatechange', onReadyStateChange);
|
||||||
|
watchForStylusButton();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
document.addEventListener('readystatechange', onReadyStateChange);
|
||||||
|
} else {
|
||||||
|
watchForStylusButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
})()
|
|
@ -89,6 +89,12 @@
|
||||||
"run_at": "document_start",
|
"run_at": "document_start",
|
||||||
"all_frames": false,
|
"all_frames": false,
|
||||||
"js": ["content/install-hook-openusercss.js"]
|
"js": ["content/install-hook-openusercss.js"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matches": ["https://userstyles.world/style/*"],
|
||||||
|
"run_at": "document_start",
|
||||||
|
"all_frames": false,
|
||||||
|
"js": ["content/install-hook-userstylesworld.js"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user