Roundheadpku / 微博搜索净化-李艺彤

// ==UserScript==
// @name        微博搜索净化-李艺彤
// @namespace   http://roundhead.info
// @include     *weibo.com/*
// @version     1.2
// @grant       GM_xmlhttpRequest
// @description 净化搜索!!!
// ==/UserScript==

var name="李艺彤"

var kw=["求佛","总选","-素颜"]
kws=localStorage.getItem('kw');
if(kws!=null){
  kw=kws.split(/[ ,]+/);
}
var dt=20;
dts=localStorage.getItem('dt');
if(dts!=null){
  dt=parseInt(dts);
}
var strange=/form_table veri_code clearfix/g
var started=false;
var count=-1;

url0="http://s.weibo.com/weibo/"
url1="?topnav=1&wvr=6&b=1"
function getTitle(rs){
  var re=/(?:<title>)([^<]*)(?:<\/title>)/g
  
  return re.exec(rs)[1]

}
var addLog=function(text){
  var ul=document.getElementById("lyts_logl");
  var li=document.createElement("li");
  li.appendChild(document.createTextNode(text)) ;
  ul.insertBefore(li,ul.firstChild);
  count+=1;
  document.getElementById("lyts_count").innerHTML=count+"";
}
var searchI=function(i){
  url=url0+encodeURIComponent(encodeURIComponent(name+" "+kw[i]))+url1
  if(kw[i][0]=='-'){
    url=url0+encodeURIComponent(encodeURIComponent(name+kw[i].slice(1)))+url1
  }
  GM_xmlhttpRequest ( {
      method:     "GET",
      url:        url,
      onload:     function (response) {
       
        if(strange.test(response.responseText)){
          alert("被新浪发现啦!请输入验证码:(");
          started=false
        }else{

          addLog(getTitle(response.responseText));
        }
      }
  } );
  
}
var searchLoop=function(i){
  if(started){
  searchI(i)
  setTimeout(function(){
    searchLoop((i+1)%kw.length)
  },dt*1000)}
}
var startLoop=function(){
  if(!started){
    addLog("启动中……");
        started=true;
    var si=Math.floor((Math.random() * kw.length) )%kw.length; 
searchLoop(si);

  }
}
function dispInfo(){
  document.getElementById("lyts_logi").style.display = "inline";
  document.getElementById("lyts_box").style.opacity=1;
}
function hideInfo(){
 document.getElementById("lyts_logi").style.display = "none"; 
    document.getElementById("lyts_box").style.opacity=.4;
}
function updateValue(){
  dt=parseInt(document.getElementById("lyts_dt").value);
  kw=document.getElementById("lyts_kw").value.split(/[ ,]+/);
  localStorage.setItem('dt', dt);
  localStorage.setItem('kw', kw.join(" "));
  console.log(kw);
  startLoop();
}
var newHTML         = document.createElement ('div');
newHTML.innerHTML   = '             \
    <div id="lyts_box">             \
        <img id="lyts_ava" src="http://tp2.sinaimg.cn/3700233717/180/5728536973/0"></img>       \
       <div id="lyts_log">\
<div id="lyts_count">\
</div>\
<div id="lyts_logi">\
<form style="width:120px;">间隔<input type="text" id="lyts_dt" value="20"/>秒,关键词<br/>\
<textarea id="lyts_kw">奇妙的约会 求佛 总选 段子 长博 拉票会 wota艺 唱吧 综艺 鸟之诗 美拍</textarea>\
<br/>\
</form>\
<ul id="lyts_logl"> \
<li id="lyts_notice">修改参数后,点击头像开始!(修改会自动保存哟~)</li>\
</ul> \
       </div>\
       </div>                    \
    </div>                          \
<style>                             \
#lyts_box{                \
position:fixed;         \
    width:50px;          \
    height:50px;            \
    left:0px;              \
    top:50px;              \
opacity:.4;\
padding:20px;\
display:table;\
}                           \
#lyts_box img{     \
width:50px;       \
height:50px;     \
cursor:pointer\
}               \
#lyts_logl{\
    height: 100px;\
    overflow: scroll;\
    width: 200px;\
}\
#lyts_logi{\
width=200px;\
}\
#lyts_count{\
background: red;\
    display: inline-block;\
    color: white;\
    font-weight: bold;\
    position: fixed;\
    top: 70px;\
left:20px;\
}\
#lyts_dt{\
width:20px;\
}\
#lyts_kw{\
width:200px;\
}\
#lyts_notice{\
color:red;\
}\
</style>                      \
';

document.body.appendChild (newHTML);
hideInfo();
ava=document.getElementById('lyts_ava');
box=document.getElementById('lyts_box');
ava.addEventListener ("click",        updateValue,  true);
box.addEventListener ("mouseover",    dispInfo,          true);
box.addEventListener ("mouseout",     hideInfo,           true);
document.getElementById('lyts_dt').value=dt
document.getElementById('lyts_kw').value=kw.join(' ')