您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Adds an "Eat" button to every comment on the website Know Your Meme, which deletes the html of that comment when clicked.
// ==UserScript== // @name Edible KYM comments // @license MIT // @description Adds an "Eat" button to every comment on the website Know Your Meme, which deletes the html of that comment when clicked. // @version 1 // @match *://knowyourmeme.com/ // @include https://knowyourmeme.com/* // @grant none // @run-at document-end // @namespace https://greasyfork.org/users/841963 // ==/UserScript== // Step 1: create button var tempElement = document.createElement('div'); tempElement.innerHTML = '<div class="edible-link-container" style="display: inline-block;padding-left: 8px;"><a class="reply-link small orange button" href="" onclick="event.preventDefault(); this.parentNode.parentNode.parentNode.parentNode.remove();">Eat</a></div>'; // Step 2: get comments var comments = document.getElementsByClassName("comment"); // Step 3: clone button to each comment for (var i = 0; i < comments.length; i++) { comments[i].children[1].children[5].appendChild(tempElement.firstChild.cloneNode(true)); } // Step 4: Create a MutationObserver to watch for changes var observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { var newNodes = Array.from(mutation.addedNodes); var traverseAndAppend = function (node) { if (node instanceof Element && node.classList.contains("comment")) { node.children[1].children[5].appendChild(tempElement.firstChild.cloneNode(true)); } var childNodes = Array.from(node.childNodes); childNodes.forEach(function (childNode) { traverseAndAppend(childNode); }); }; newNodes.forEach(function (newNode) { traverseAndAppend(newNode); }); }); }); // Step 5: Configure and start observing for changes var config = { childList: true, subtree: true }; observer.observe(document.body, config);