Created
June 15, 2021 03:17
-
-
Save dclamage/67be425c4a4383a761b3cea978559232 to your computer and use it in GitHub Desktop.
Adds puzz.link buttons to the database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name puzz.link Add link | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Adds puzz.link buttons to the database | |
// @author RSP | |
// @match https://puzz.link/db* | |
// @icon https://puzz.link/favicon-32x32.png | |
// @grant none | |
// @run-at document-idle | |
// ==/UserScript== | |
/* script adapted from Lavaloid's modification of Eric Fox's original script */ | |
(function() { | |
'use strict'; | |
let lk = []; | |
let last = ''; | |
setInterval(function() { | |
let now = document.getElementsByTagName('img')[0] ?? {}; | |
if (now.src !== last) lk = add_puzzlinks(); | |
last = now; | |
}, 1000); | |
//create openall button | |
let openall = document.createElement('button'); | |
openall.addEventListener('click', () => { | |
lk = add_puzzlinks(); | |
lk.forEach((l) => window.open(l)); | |
}); | |
openall.innerText = 'open all'; | |
document.getElementsByClassName('paging')[0].appendChild(openall); | |
})(); | |
function add_puzzlinks() { | |
let links = []; | |
[...document.getElementsByClassName('pzvpuzzle')].forEach((pz) => { | |
let link = pz.getElementsByTagName("img")[0].src.replace("v?thumb&","?"); | |
if (!pz.getElementsByClassName('plink').length) { | |
pz.insertAdjacentHTML('beforeend', '<div class="plink"><a target="_blank" href="' + link + '">[puzz.link]</a></div>'); | |
pz.getElementsByTagName('a')[0].href = link; | |
} | |
links.push(link); | |
}); | |
return links; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment