0
0
mirror of https://github.com/Maks1mS/userscripts.git synced 2024-12-23 16:22:59 +03:00

[QuarklyUploadImageViaURL] Add support for SPA navigation

This commit is contained in:
Maxim Slipenko 2023-08-04 14:22:29 +03:00 committed by GitHub
parent 9350ae160e
commit 555fa1876a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,13 +1,14 @@
// ==UserScript== // ==UserScript==
// @name Quarkly Upload Image via URL // @name Quarkly Upload Image via URL
// @namespace https://github.com/Maks1mS/userscripts // @namespace https://github.com/Maks1mS/userscripts
// @version 0.2 // @version 0.3
// @description try to take over the world! // @description try to take over the world!
// @author Maxim Slipenko // @author Maxim Slipenko
// @match https://quarkly.io/project/* // @match https://quarkly.io/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=quarkly.io // @icon https://www.google.com/s2/favicons?sz=64&domain=quarkly.io
// @grant GM_xmlhttpRequest // @grant GM_xmlhttpRequest
// @grant GM_addStyle // @grant GM_addStyle
// @grant window.onurlchange
// ==/UserScript== // ==/UserScript==
(function() { (function() {
@ -15,6 +16,7 @@
const QUARKLY_UPLOAD_BUTTON_ID = 'upload-image-button'; const QUARKLY_UPLOAD_BUTTON_ID = 'upload-image-button';
const UPLOAD_BY_URL_ID = 'upload-image-button-by-url'; const UPLOAD_BY_URL_ID = 'upload-image-button-by-url';
const QUARKLY_PROJECT_URL_PREFIX = 'https://quarkly.io/project/'
function insertAfter(newNode, existingNode) { function insertAfter(newNode, existingNode) {
existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling); existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
@ -70,6 +72,10 @@
return button return button
} }
// TODO: better popup detection
let timer;
function run() { function run() {
const dest = document.querySelector(`label[for="${QUARKLY_UPLOAD_BUTTON_ID}"]`); const dest = document.querySelector(`label[for="${QUARKLY_UPLOAD_BUTTON_ID}"]`);
if (dest) { if (dest) {
@ -79,7 +85,15 @@
} }
} }
setInterval(run, 2500); if (window.onurlchange === null) {
window.addEventListener('urlchange', (info) => {
if (info?.url?.startsWith(QUARKLY_PROJECT_URL_PREFIX)) {
timer = setInterval(run, 3000);
} else {
clearInterval(timer);
}
});
}
var css = ` var css = `
#${UPLOAD_BY_URL_ID} { #${UPLOAD_BY_URL_ID} {