3/29/2020, 5:46:18 PM
目前為
// ==UserScript==
// @name TJ User Tagging
// @namespace Violentmonkey Scripts
// @match https://tjournal.ru/*
// @grant none
// @version 1.4
// @author -
// @description 3/29/2020, 5:46:18 PM
// ==/UserScript==
function setTag(userId){
let tags = JSON.parse(localStorage.userTags || '{}');
let newTag = prompt('Тег, или тег#цвет:', tags[userId]);
if (newTag == null) return;
localStorage.userTags = JSON.stringify(Object.assign(tags, {[userId]: newTag }), (k, v) => v ? v : void 0);
tagsUpdate();
}
function addTagButton(){
let target = document.querySelector('.etc_control[data-subsite-url]');
if (target && !document.querySelector('._tg')) {
with (target.insertAdjacentElement('afterend', document.createElement('div'))){
onclick = () => /\/(\d+)-/.test(location.href) && setTag(RegExp.$1);
className = '_tg';
}
}
setTimeout(addTagButton, 500);
}
function tagsUpdate(){
let tags = JSON.parse(localStorage.userTags || '{}');
(window._tgStyle || (window._tgStyle = document.body.appendChild(document.createElement('style')))).innerHTML = `
.user_name:after, .content-header-author:after, .vote__users__item .vote__users__item__name:after { display: inline-block; padding: 2px 4px 3px 4px; margin: -2px 4px -3px 4px; border-radius: 2px; font-weight: normal; font-size: small; }
.etc_control[data-subsite-url] + ._tg:after { content: "Тег"; color: #000; background: #fff; height: 34px; line-height: 34px; font-size: 15px; padding: 0 20px; border-radius: 4px; border: 1px solid rgba(0,0,0,.15); display: inline-block; font-weight: normal; margin-left: 8px; cursor: pointer; }
` + Object.keys(tags).filter(x => tags[x]).map(x => `a[href*="/${x}-"] .user_name:after, .vote__users__item[href*="/${x}-"] .vote__users__item__name:after, .content-header-author[href*="/${x}-"]:after, .etc_control[data-subsite-url*="/${x}-"] + ._tg:after { content: "${tags[x].split('#')[0]}"; background: #${tags[x].split('#')[1] || 'a00'}; color: #${!tags[x].split('#')[1] || parseInt(tags[x].split('#')[1].substr(2, 2), 16) < 200 ? 'fff' : '000'}; }`).join('\n');
}
addTagButton();
tagsUpdate();