Created
May 29, 2019 09:11
-
-
Save greatghoul/394646c1caf92143686ed04c01cdfbae to your computer and use it in GitHub Desktop.
Tower 高亮自己的今天的任务
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Tower 高亮我的任务 | |
// @namespace greatghoul | |
// @version 0.1 | |
// @description | |
// @author greatghoul | |
// @match https://tower.im/* | |
// @grant none | |
// ==/UserScript== | |
/* global $, waitForKeyElements */ | |
(function() { | |
const NICKNAME = /邱建/ | |
const TODAY = /今天/ | |
const installStyles = () => { | |
const style = document.createElement('style') | |
style.innerHTML = ` | |
.todo[data-highlight] { | |
background-color: #fbfbdb | |
} | |
` | |
document.querySelector('head').appendChild(style) | |
} | |
const isAssignee = (todo) => { | |
const nickname = todo.querySelector('.todo-assignee') | |
return nickname && NICKNAME.test(nickname.innerText) | |
} | |
const isDueToday = (todo) => { | |
const dueDate = todo.querySelector('.due-date') | |
return dueDate && TODAY.test(dueDate.innerText) | |
} | |
const isOutdated = (todo) => { | |
const outdated = todo.querySelector('.tr-todo-date-field[outdate]') | |
return !!outdated | |
} | |
const processTodo = (todo) => { | |
if (isAssignee(todo) && (isDueToday(todo) || isOutdated(todo))) { | |
todo.setAttribute('data-highlight', 'true') | |
} else { | |
todo.removeAttribute('data-highlight') | |
} | |
} | |
const startProcessor = () => { | |
timer && window.clearTimeout(timer) | |
const todos = document.querySelectorAll('.todo') | |
todos.forEach(processTodo) | |
timer = window.setTimeout(() => startProcessor(), 2000) | |
} | |
let timer = null | |
const init = () => { | |
installStyles() | |
startProcessor() | |
} | |
init() | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment