From 16648e7407a862ab40f412763883e59cd093ffcc Mon Sep 17 00:00:00 2001 From: De Rais Date: Mon, 19 Jun 2017 01:06:38 -0400 Subject: [PATCH] userscript: make "No. 123" links smarter --- example/rb-79.user.js | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/example/rb-79.user.js b/example/rb-79.user.js index 7fe165a..6b53199 100644 --- a/example/rb-79.user.js +++ b/example/rb-79.user.js @@ -13,21 +13,44 @@ var video_re = /\.(webm|mkv|mp4|mp3|ogg|m4a|flac|opus|mka)$/i; /* * Turn off any sort of link for the userscript that's being advertised */ -document.querySelectorAll('.userscript-link').forEach(function(b) { +document.querySelectorAll('.userscript-link').forEach(function (b) { b.parentNode.removeChild(b); }); /* - * Turn all post numbers into clickable links, for quoting + * Turn all post numbers into clickable links, for quoting and thread-jumping */ -document.querySelectorAll('span.post-number').forEach(function (s) { - s.onclick = function () { - document.querySelectorAll('textarea[name=comment]').forEach(function (t) { - t.value = t.value + '>>' + s.innerText.replace(/No. +/, '') + '\n'; - }); - }; - s.innerHTML = '' + s.innerHTML + ''; -}); +if (window.location.href.includes('/res/')) { + document.querySelectorAll('span.post-number').forEach(function (s) { + s.onclick = function () { + document.querySelectorAll('textarea[name=comment]').forEach(function (t) { + t.value = t.value + '>>' + s.innerText.replace(/No. +/, '') + '\n'; + }); + }; + s.innerHTML = '' + s.innerHTML + ''; + }); +} else { + document.querySelectorAll('div.thread_preview').forEach(function (d) { + var thread_url = ''; + for (var j = 0; j < d.children.length; j++) { + var c = d.children[j]; + if (c.className == 'op-post') { + c.querySelectorAll('a').forEach(function (a) { + if (a.href.includes('/res/')) { + thread_url = a.href; + } + }); + } + if (c.className == 'op-post' || c.className == 'reply-container') { + c.querySelectorAll('span.post-number').forEach(function (s) { + var post_number = s.innerText.replace(/No. +/, ''); + s.innerHTML = '' + s.innerHTML + ''; + }); + } + } + }); +} /* * Shift+Click to remove files -- 2.11.4.GIT