-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnonograms_inner_navigation_size.user.js
56 lines (43 loc) · 1.71 KB
/
nonograms_inner_navigation_size.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// ==UserScript==
// @name Nonograms.org inner navigation - (by Size)
// @namespace https://github.com/Dorifor
// @version 2024-11-11
// @description I just wanted to easily go to the next puzzle when finished
// @author mao
// @match https://www.nonograms.org/nonograms/i/*
// @match https://www.nonograms.org/nonograms2/i/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=nonograms.org
// @grant none
// ==/UserScript==
function createButton(label, link) {
const a = document.createElement("a");
a.href = link;
a.style.paddingRight = '5px';
const button = document.createElement("button");
button.innerHTML = label;
a.appendChild(button);
return a;
}
function redirectIf404() {
if (document.querySelector('#nonogram_page_announcement'))
{
return;
}
const url = window.location.href;
const isColored = window.location.pathname.split('/')[1] == 'nonograms2'
const redirectUrl = isColored ? url.replace('nonograms2/', 'nonograms/') : url.replace('nonograms/', 'nonograms2/')
window.location.replace(redirectUrl);
}
(function() {
'use strict';
redirectIf404();
const linksContainer = document.querySelector('#nonogram_page_announcement');
// document.querySelectorAll('.nonogram_title')[1].href
fetch('https://www.nonograms.org/search?name=&colors=1&sort=3&skip_solved=1').then(res => res.text()).then(html => {
let parser = new DOMParser();
let doc = parser.parseFromString(html, 'text/html');
let link = doc.querySelectorAll('.nonogram_title')[1].href;
const nextButton = createButton('Next', link);
linksContainer.appendChild(nextButton);
})
})();