Last active
January 6, 2024 14:00
-
-
Save evdokimovm/e3c513b3c8f01cac8118f024ac1d88bb to your computer and use it in GitHub Desktop.
replies on 4chan will be closed only when you click on them
This file contains hidden or 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 4ChReplies (Improve Replies) | |
// @namespace 4ChReplies | |
// @version 1.0 | |
// @description Make navigate on 4chan replies more comfortable with this script for tampermonkey. Now replies closes only by click on it. | |
// @author https://github.com/evdokimovm | |
// @match https://boards.4chan.org/* | |
// @match https://boards.4channel.org/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
var references = document.querySelectorAll('.quotelink') | |
var already_opens = [] | |
// var already_opens_elements = [] | |
window.addEventListener('mouseout', function(event) { | |
event.stopImmediatePropagation() | |
}, true) | |
window.addEventListener('mouseover', function(event) { | |
event.stopImmediatePropagation() | |
}, true) | |
// Make replies that appears on update works as expected after Re:Assign | |
var navlinks = document.querySelector('.navLinksBot') | |
var new_a = document.createElement('a') | |
var lb = document.createTextNode(' [') | |
var linkText = document.createTextNode('Re:Assign') | |
var rb = document.createTextNode(']') | |
new_a.appendChild(linkText) | |
new_a.style.cursor = 'pointer' | |
new_a.addEventListener('click', function(e) { | |
update(document.querySelectorAll('.quotelink')) | |
}) | |
navlinks.appendChild(lb) | |
navlinks.appendChild(new_a) | |
navlinks.appendChild(rb) | |
function update(references) { | |
references.forEach(element => { | |
element.addEventListener('mouseenter', function(e) { | |
var id = `#p${element.textContent.substring(2)}` | |
if (!already_opens.includes(id) && !id.includes('(OP)')) { | |
already_opens.push(id) | |
var width_of_clone_element = document.querySelector(`#p${element.textContent.substring(2)}`).offsetWidth | |
var clone_element = document.querySelector(`#p${element.textContent.substring(2)}`).cloneNode(true) | |
clone_element.style.display = 'block' | |
clone_element.style.position = 'absolute' | |
clone_element.style.padding = '3px 6px 6px 3px' | |
clone_element.style.margin = '0' | |
clone_element.classList.add('post') | |
clone_element.classList.add('reply') | |
clone_element.classList.add('preview') | |
clone_element.classList.add('reveal-spoilers') | |
clone_element.style.zIndex = 300 | |
/* if (width_of_clone_element > (document.body.offsetWidth / 1.3)) { | |
clone_element.style.left = 50 + 'px' | |
} | |
else */if (e.pageX >= (document.body.offsetWidth / 2)) { | |
clone_element.style.left = (e.pageX - ((width_of_clone_element >= (document.body.offsetWidth / 2)) ? (width_of_clone_element / 2) : width_of_clone_element)) + 'px' | |
} | |
else { | |
clone_element.style.left = e.pageX + 'px' | |
} | |
clone_element.style.top = e.pageY + 'px' | |
clone_element.addEventListener('click', function(e) { | |
if (!window.getSelection().isCollapsed) { | |
return | |
} | |
// not close reply when click on image | |
if (!e.target.src) { | |
already_opens = already_opens.filter((item) => item !== ('#' + this.id)) | |
this.remove() | |
} | |
}) | |
clone_element.style.setProperty("border", "1px solid black", "important") | |
clone_element.style.setProperty("background-color", "#e7e7e7") | |
document.querySelector('body').appendChild(clone_element) | |
/* already_opens_elements.push(clone_element) | |
if (already_opens_elements.length >= 3) { | |
var d = already_opens_elements.shift() | |
already_opens = already_opens.filter((item) => item !== ('#' + d.id)) | |
d.remove() | |
} */ | |
update(clone_element.querySelectorAll('.quotelink')) | |
} | |
}) | |
}) | |
} | |
update(references) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment