// ==UserScript== // @name 自动图标 // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match https://mubu.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=mubu.com // @grant none // ==/UserScript== (function() { 'use strict'; //更新元素下面所有bullet-dot节点 function displayIcon(item){ //查找所有bullet-dot节点 var bullets = item.querySelectorAll("div.bullet-dot"); bullets.forEach (function (bullet) { //隐藏原来显示的圆点 bullet.style.top = "0px"; bullet.style.left = "0px"; bullet.style.width = "0px"; bullet.style.height = "0px"; //为节点添加图标 var r = bullet.parentNode.parentNode.nextElementSibling.nextElementSibling.innerText.match(/联系|安排|等待|考虑|撰写|组织|审核|编写|截止|查看|完成|制订/); if (r){ //根据关键字设置图标 var icons = {"联系":"📞", "安排":"➡️", "等待":"⌛", "考虑":"💡", "撰写":"📝", "组织":"⛺", "审核":"💻", "编写":"📝","制订":"📝", "截止":"📅", "完成":"📅","查看":"💻"}; bullet.innerText = icons[r[0]]; } else{ //没有关键字的设置文件夹图标 var l = bullet.parentNode.parentNode.parentNode.parentNode.parentNode.classList; if(l.contains("collapsed") || l.contains("no-children")){ //没有展开的节点显示关闭的文件夹 bullet.innerText = "📁"; } else{ //展开的节点显示打开的文件夹 bullet.innerText = "📂"; } } }) } //延时等待页面准备好 function waitForReady(){ var pane = document.getElementById("js-outliner"); if(pane){ //查找到列表则更新全部列表 displayIcon(document); //设置监视列表变化 var paneconfig = {characterData:true, childList:true, subtree:true}; var paneobserver = new MutationObserver(function (mutationsList, observer) { //处理所有的列表变化 for(var i = 0; i < mutationsList.length; i++){ var mutation = mutationsList[i]; console.log("开始更新:" + mutation.target + " " + mutation.type); if(mutation.type == "characterData"){ //如果是文本变化更新上级节点 displayIcon(mutation.target.parentNode.parentNode.parentNode); } else{ //如果是节点列表更新,则更新所有增加的节点 if(mutation.target.classList.contains("outliner-tree-content")){ mutation.addedNodes.forEach(function(item){ if (item.classList.contains("outliner-node")){ displayIcon(item); } }) } } } }); paneobserver.observe(pane, paneconfig); } else{ //没有查找到列表则继续等待 setTimeout(waitForReady, 500); } } //设置延时等待 setTimeout(waitForReady, 500); })();