Last active
January 29, 2024 02:24
-
-
Save hookbin/2c769fac974ce412578036c543db7fd1 to your computer and use it in GitHub Desktop.
JIRA内容变化监测器
This file contains hidden or 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 JIRA内容变化监测器 | |
| // @namespace https://www.hookbin.top | |
| // @version 1.2 | |
| // @description 监测JIRA内容是否发生变化,并发送浏览器通知 | |
| // @match http://jira.ecarxgroup.com/* | |
| // @match https://jira.ecarxgroup.com/* | |
| // @updateURL https://gist.githubusercontent.com/hookbin/2c769fac974ce412578036c543db7fd1/raw/c566548164ecf3faf79ac70c84b678184dfb63ce/jira-notify.js | |
| // @downloadURL https://gist.githubusercontent.com/hookbin/2c769fac974ce412578036c543db7fd1/raw/c566548164ecf3faf79ac70c84b678184dfb63ce/jira-notify.js | |
| // @grant GM_xmlhttpRequest | |
| // @grant GM_setValue | |
| // @grant GM_getValue | |
| // @require https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js | |
| // ==/UserScript== | |
| if (window != window.top) { | |
| return; | |
| } | |
| (function() { | |
| 'use strict'; | |
| var previousContent = ''; | |
| let TIME_INTERVAL = 10000; | |
| let KEY_LAST_REQUEST_TIME = "LAST_REQUEST_TIME"; | |
| // 每分钟执行一次 | |
| setInterval(function() { | |
| var lastRequestTime = GM_getValue(KEY_LAST_REQUEST_TIME); | |
| console.log("lastRequestTime", lastRequestTime) | |
| var currentTime = new Date().getTime(); | |
| try{ | |
| // 执行节流,每次request的间隔时间需要大于10000 | |
| if(lastRequestTime || currentTime - parseInt(lastRequestTime)> TIME_INTERVAL){ | |
| GM_setValue(KEY_LAST_REQUEST_TIME, currentTime); | |
| }else{ | |
| return; | |
| } | |
| }catch(e){ | |
| } | |
| request(); | |
| }, TIME_INTERVAL); | |
| function request(){ | |
| GM_xmlhttpRequest({ | |
| method: "GET", | |
| url: "https://jira.ecarxgroup.com/sr/jira.issueviews:searchrequest-rss/temp/SearchRequest.xml?jqlQuery=assignee+%3D+currentUser%28%29+AND+resolution+%3D+Unresolved+order+by+updated+DESC&tempMax=80000", | |
| onload: function(response) { | |
| // console.log("response", response) | |
| // console.log("response.responseText", response.responseText) | |
| // 计算MD5哈希值 | |
| var currentContent = CryptoJS.MD5(removeFirstThreeLines(response.responseText)).toString(); | |
| console.log("previousContent", previousContent,"currentContent", currentContent) | |
| if (previousContent && currentContent !== previousContent) { | |
| sendBrowserNotification("JIRA CHANGE"); | |
| } | |
| previousContent = currentContent; | |
| } | |
| }); | |
| } | |
| // 忽略前三行 | |
| function removeFirstThreeLines(str) { | |
| var lines = str.split('\n'); | |
| if (lines.length >= 3) { | |
| lines.splice(0, 3); | |
| } | |
| return lines.join('\n'); | |
| } | |
| // 发送通知 | |
| function sendBrowserNotification(message) { | |
| var notification | |
| if (Notification.permission === "granted") { | |
| notification = new Notification(message, { | |
| body: message | |
| }); | |
| } else if (Notification.permission !== "denied") { | |
| Notification.requestPermission().then(function(permission) { | |
| if (permission === "granted") { | |
| notification = new Notification(message, { | |
| body: message | |
| }); | |
| } | |
| }); | |
| } | |
| if(notification){ | |
| // 监听通知点击事件 | |
| notification.addEventListener('click', function() { | |
| // 打开指定的网页 | |
| window.open('https://jira.ecarxgroup.com/issues/?filter=-1'); | |
| // 关闭通知 | |
| notification.close(); | |
| }); | |
| } | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment