// ==UserScript== // @name Qiita Sushi // @namespace https://greasyfork.org/users/432749 // @description QiitaのLGTMアイコンをSushiアイコンに変更する // @author fukuchan // @match https://qiita.com/* // @version 0.0.1.20200313025308 // @downloadURL none // ==/UserScript== /* * OpenSushi * (c) remin */ const viewBox = '0 0 64 64'; const innerHTML = 'Sushi'; // SVG要素の中身をSushiに変更するメソッド const replaceSvg = svg => { svg.setAttribute('viewBox', viewBox); svg.innerHTML = innerHTML; }; // SVG要素やテキストのLGTMを発見し、全てSUSHIに変更するメソッド const sushinize = node => { // LGTMのSVG要素をそれぞれSushiに変更し、要素の変更を監視する const images = node.querySelectorAll('*[class*="like"] svg, .ItemLink__status svg, .ms-ItemList_counts svg'); images.forEach(image => { replaceSvg(image); new MutationObserver((records, observer) => { observer.disconnect(); replaceSvg(records[0].target); observer.observe(records[0].target, {attributes: true}); }).observe(image, {attributes: true}); }); // 文字列のLGTMをSushiに置換する const texts = node.querySelectorAll('.userPopularItems_likeUnit, .notification_actionWrapper span.bold:last-of-type, .tst-ArticleList_subLabel, a[href*=like], .ms-ItemHeader_likedCount'); texts.forEach(text => { text.textContent = text.textContent.replace('LGTM', 'Sushi'); }); }; // 現在読み込まれているdocument中のLGTMを全てSUSHIに置換 sushinize(document); // コメントなど遅延読み込みされる動的な要素中のLGTMを読み込まれると同時に全てSUSHIに置換 const dynamicNodes = document.querySelectorAll('#comments, *[class*=List_view], div[data-hyperapp-app="Milestones"]'); dynamicNodes.forEach(node => { new MutationObserver(() => sushinize(node)).observe(node, {childList: true}); });