Created
May 13, 2017 08:09
-
-
Save jacky-q/6bf5fe4879549ac2c2863ce0575b6ade to your computer and use it in GitHub Desktop.
投标警示器,监控界面是否出现用户设定关键字
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 ProgrameAlert | |
// @namespace net.jacky.p2p | |
// @description 扫标器 | |
// @include https://www.zyxr.com/invest/share_program.html* | |
// @version 1 | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// @grant GM_registerMenuCommand | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
var $ = function(id){ | |
return document.getElementById(id); | |
} | |
var intervalObj = null; | |
function init(){ | |
console.log('-----start'); | |
console.log('p2p_'+getHost() +"->" +GM_getValue('p2p_'+getHost() )); | |
addCmd('添加标的关键字',registerItem); | |
var item = GM_getValue('p2p_'+getHost() ); | |
searchItem(item); | |
console.log('-----end') | |
} | |
function addCmd(title,func){ | |
GM_registerMenuCommand(title,func); | |
} | |
function registerItem(){ | |
var host = getHost(); | |
var item = window.prompt('添加关键字',GM_getValue('p2p_' +host)); | |
if(item != null){ | |
GM_setValue('p2p_'+host,item); | |
window.location.reload(); | |
} | |
} | |
function getHost(){ | |
var h = document.location.href; | |
h = h.substring( h.indexOf("://")+3); | |
var host = h.substring(0,h.indexOf("/")); | |
return host; | |
} | |
function searchItem(key){ | |
var t = searchAndAlert(key); | |
intervalObj = window.setInterval(t,30 * 1000); | |
} | |
function searchAndAlert(key){ | |
return function(){ | |
console.log('searching...'); | |
getWebContent(); | |
} | |
} | |
function getWebContent(){ | |
var url = window.location.href; | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: url, | |
onload: function(response) { | |
var content = (response.responseText); | |
console.log(content); | |
var key = GM_getValue('p2p_' +getHost()); | |
if(content.indexOf(key) > 0){ | |
alert('出现' + key + '了!'); | |
window.clearInterval(intervalObj); | |
} | |
} | |
}); | |
return 'GM_xmlhttpRequest'; | |
} | |
window.addEventListener('load', init,true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment