Anonymous ID: f83055 April 2, 2019, 10:20 p.m. No.6027782   🗄️.is 🔗kun

jsanon here

 

this post contains a userscript for Greasemonkey, Tampermonkey, etc that makes some improvements to the breads

 

more info about userscripts and how to install them: https://github.com/OpenUserJs/OpenUserJS.org/wiki/Userscript-Beginners-HOWTO

 

features so far:

 

  • highlight all lb/pb links in yellow

  • add "(OP)" in header of replies by the original poster

  • fix loading .jpeg thumbnails from previous breads

 

pic related

 

// —————– BEGIN SCRIPT

 

// UserScript

// @name qresearch tweaks by jsanon

// @version 7709

// @grant none

// @include https://8ch.net/qresearch/*

// /UserScript

 

(function() {

/**

  • Helper functions

*/

function addStyle(css) {

var style = document.createElement('style');

style.innerHTML = css;

document.querySelector('head').appendChild(style);

}

 

/**

  • Highlight lb/pb links in yellow

*/

var opPostIDMatch = window.location.href.match(/\/(\d+).html/);

if (!opPostIDMatch) {

// Not on an individual thread page; stop here.

return;

}

var opPostID = opPostIDMatch[1];

addStyle(`

a[href^="/qresearch/res/"]:not([href^="/qresearch/res/${opPostID}.html"]) {

background: #ffb;

}

`);

 

/**

  • Add "(OP)" to OP user ID

*/

var opPosterID = document.querySelector('.post.op .poster_id').innerText.trim();

function highlightPostsByOPUser() {

Array.from(document.querySelectorAll('span.poster_id:not(.poster_id_checked)'))

.forEach(el ={

var posterID = el.innerText.trim();

if (posterID === opPosterID) {

el.classList.add('poster_id_op');

el.style.fontWeight = 'bold';

el.parentNode.insertBefore(document.createTextNode(' (OP)'), el.nextSibling);

}

el.classList.add('poster_id_checked');

});

}

highlightPostsByOPUser();

setInterval(highlightPostsByOPUser, 2000);

 

/**

  • Fix loading .jpeg images from previous breads

*/

function fixJpegImages() {

Array.from(document.querySelectorAll('div.post.post-hover'))

.forEach(el ={

var fileinfoName = el.querySelector('p.fileinfo a:not(.hide-image-link)');

var img = el.querySelector('img');

console.log( { el, text: fileinfoName.innerText, src: img.src } );

if (/.jpeg\s*$/.test(fileinfoName.innerText) &&

/.jpg$/.test(img.src)) {

img.src = img.src.replace(/.jpg$/, '.jpeg');

}

});

}

setInterval(fixJpegImages, 1000);

})();

 

// —————– END SCRIPT