Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name 2ch replacement
- // @version 1
- // @grant none
- // @include https://2ch.hk/po/*
- // @include https://2ch.life/po/*
- // ==/UserScript==
- const replacements = new Map([
- ['img[title="Коммунизм"] + img[src="/flags/A1.png"]', 'Ко-ко-ко!'],
- ]);
- function processPost(postEl) {
- for (const [query, replace] of replacements) {
- if (postEl.querySelector(query)) {
- postEl.querySelector('.post__message').textContent = replace;
- return;
- }
- }
- }
- function processThread(thrEl) {
- for (const el of thrEl.querySelectorAll('.post_type_reply')) {
- processPost(el);
- }
- if (document.URL.includes('/res/')) {
- const observer = new MutationObserver((mutationList, observer) => {
- console.log('mutation');
- for (const mutation of mutationList) {
- for (const el of mutation.addedNodes) {
- if (el.classList.contains('post_type_reply')) {
- processPost(el);
- }
- }
- }
- });
- observer.observe(thrEl, {childList: true});
- }
- }
- function runScript() {
- for (const el of document.querySelectorAll('.thread')) {
- processThread(el);
- }
- }
- if(document.readyState !== 'loading') {
- runScript();
- } else {
- document.addEventListener('DOMContentLoaded', runScript);
- }
Add Comment
Please, Sign In to add comment