Baidu Multiuser

百度马甲切换

  1. // ==UserScript==
  2. // @name Baidu Multiuser
  3. // @namespace http://gera2ld.blog.163.com/
  4. // @author Gerald <gera2ld@163.com>
  5. // @icon http://ww2.sinaimg.cn/small/a56031a1gw1emwlbe1c8gj2097097wfa.jpg
  6. // @version 2.0.1
  7. // @description 百度马甲切换
  8. // @homepageURL http://geraldl.net/userjs/BaiduMultiuser
  9. // @match *://*.baidu.com/*
  10. // @include *.baidu.com/*
  11. // @exclude http://developer.baidu.com/*
  12. // @exclude http://web.im.baidu.com/*
  13. // @grant GM_addStyle
  14. // @grant GM_getValue
  15. // @grant GM_setValue
  16. // @grant GM_xmlhttpRequest
  17. // @grant GM_registerMenuCommand
  18. // ==/UserScript==
  19.  
  20. function getValue(key,def){
  21. var v=GM_getValue(key)||'';
  22. try{v=JSON.parse(v);}catch(e){v=def;}
  23. return v;
  24. }
  25. function setValue(k,v){GM_setValue(k,JSON.stringify(v));}
  26. function checkCookie(name){
  27. m=document.cookie.match(/BDUSS=(.*?)(;|$)/);
  28. if(m) {users[name]=m[1];saveUsers();}
  29. else users=null;
  30. }
  31. function doSetCookie(s){
  32. var d=new Date();
  33. if(s) d.setTime(16094e8); else s='';
  34. document.cookie='BDUSS='+s+';domain=baidu.com;path=/;expires='+d.toGMTString();
  35. }
  36. function setCookie(s){
  37. var re=/\bBDUSS=/;
  38. if(re.test(document.cookie)) {
  39. doSetCookie(s);
  40. return true;
  41. }
  42. doSetCookie(s?s:'logout');
  43. if(re.test(document.cookie)) {
  44. if(!s) doSetCookie(s);
  45. return true;
  46. }
  47. }
  48. function switchUser(s,p){
  49. if(setCookie(s)) {
  50. if(typeof p=='function') p();
  51. else if(typeof p=='string') location.replace(p);
  52. else location.reload();
  53. } else alert('设置Cookie失败,请使用此脚本重新登录(不可用)!');
  54. }
  55. function initLoc(){
  56. gu.right=gu._right=gu.parentNode.offsetWidth-gu.offsetWidth-gu.offsetLeft;
  57. gu.top=gu._top=gu.offsetTop;
  58. }
  59. function saveUsers(){setValue('ge_users',users);}
  60. function saveLoc(){setValue('ge_users_loc',{right:gu.right,top:gu.top});}
  61. function checkLogIn(res){
  62. if(res.finalUrl.substr(0,url_login.length)==url_login)
  63. logIn(res.responseText);
  64. else GM_xmlhttpRequest({
  65. method:'GET',
  66. url:'http://www.baidu.com',
  67. onload:function(o){
  68. var m=o.responseText.match(/<span class=user-name>(.*?)<\/span>/);
  69. if(m) {
  70. checkCookie(m[1]);
  71. location.reload();
  72. } else alert('出错了!我也不知道要怎么办。。');
  73. },
  74. });
  75. }
  76. function doLogIn(data){
  77. console.log('do log in');
  78. var rdata=[],i;
  79. data['username']=i=prompt('请输入手机号/邮箱/用户名:');
  80. if(i===null) return;
  81. data['password']=i=prompt('请输入密码(用后即焚):');
  82. if(i===null) return;
  83. for(i in data)
  84. rdata.push(encodeURIComponent(i)+'='+encodeURIComponent(data[i]));
  85. GM_xmlhttpRequest({
  86. method:'POST',
  87. url:'http://wappass.baidu.com/passport/login',
  88. data:rdata.join('&'),
  89. headers:{
  90. 'User-Agent':User_Agent,
  91. 'Content-Type':'application/x-www-form-urlencoded',
  92. },
  93. onload:checkLogIn,
  94. });
  95. }
  96. function extractData(src){
  97. var i=src.indexOf('<div id="error_area"'),j=src.indexOf('</div>',i),
  98. m=src.substr(i,j-i).match(/<span class="highlight">(.*?)<\/span>/),
  99. data={},form;
  100. if(m) return alert('登录(不可用)失败:'+m[1]);
  101. i=src.indexOf('<form action="/passport/login"');j=src.indexOf('</form>',i);
  102. form=src.substr(i,j-i);
  103. form.replace(/<input [^>]*>/g,function(m){
  104. var o={};
  105. m.replace(/(\w+)="(.*?)"/g,function(m,g1,g2){
  106. o[g1]=g2;
  107. });
  108. if(o.type!='submit') data[o.name]=o.value;
  109. });
  110. data.submit='登录(不可用)';
  111. if(data['vcodestr']) {
  112. form=document.createElement('form');
  113. form.className='ge_popup ge_opt';
  114. form.style.display='block';
  115. form.innerHTML='\
  116. <h3>马甲切换</h3>\
  117. 请输入验证码:<input type=text class=vcode><br>\
  118. <img src=http://wappass.baidu.com/cgi-bin/genimage?'+data['vcodestr']+' style="cursor:pointer" title="看不清,换一张">\
  119. <input type=submit>';
  120. form.onsubmit=function(e){
  121. e.preventDefault();
  122. data['verifycode']=form.querySelector('.vcode').value;
  123. doLogIn(data);
  124. };
  125. form.querySelector('img').onclick=function(){
  126. setTimeout(logIn,0);
  127. };
  128. } else doLogIn(data);
  129. }
  130. function logIn(){
  131. console.log('log in');
  132. GM_xmlhttpRequest({
  133. method:'GET',
  134. url:url_login+'?type=1',
  135. headers:{
  136. 'User-Agent':User_Agent,
  137. },
  138. onload:function(o){
  139. if(!o.finalUrl) {
  140. alert('您的运行环境不支持此脚本,可以尝试Baidu Multiuser Unsafe。');
  141. return;
  142. }
  143. extractData(o.responseText);
  144. },
  145. });
  146. }
  147. function userManage(e,p,o){
  148. e.preventDefault();o=e.target;e=o.parentNode;p=e.parentNode;
  149. if(o.tagName=='A') {
  150. if(e==p.firstChild) switchUser();
  151. else if(e==p.lastChild) logIn();
  152. else switchUser(users[o.innerText||o.textContent]);
  153. } else if(o.tagName=='SPAN') {
  154. o=o.previousSibling;delete users[o.innerText||o.textContent];
  155. setTimeout(saveUsers,0);p.removeChild(e);
  156. }
  157. }
  158. function locate(l){
  159. if(l) {
  160. gu.right=l&&!isNaN(l.right)?l.right:100;
  161. gu.top=l&&!isNaN(l.top)?l.top:100;
  162. }
  163. gu.style.right=gu.right+'px';
  164. gu.style.top=gu.top+'px';
  165. }
  166. function mousemove(e){
  167. e.preventDefault();e.stopPropagation();
  168. var l={right:gu._right+gu.x-e.pageX,top:gu._top+e.pageY-gu.y};
  169. locate(l);
  170. }
  171. function pinUpdate(){
  172. if(gu.pin) {
  173. symbol.classList.add('ge_pin');
  174. symbol.setAttribute('title','固定在页面上');
  175. gu.style.position='absolute';
  176. } else {
  177. symbol.classList.remove('ge_pin');
  178. symbol.setAttribute('title','固定在屏幕上');
  179. gu.style.position='';
  180. }
  181. }
  182. function pin(){
  183. initLoc();
  184. if(gu.pin) // fixed => absolute
  185. gu.top+=window.pageYOffset;
  186. else // absolute => fixed
  187. gu.top-=window.pageYOffset;
  188. pinUpdate();
  189. locate();
  190. saveLoc();
  191. }
  192. function init(){
  193. users=getValue('ge_users',{});
  194. GM_registerMenuCommand('百度马甲设置',showOptions);
  195. GM_addStyle('\
  196. #ge_u{display:block;padding:10px;text-align:left;}\
  197. #ge_u .ge_h{display:none;}\
  198. #ge_u{z-index:10006;font:normal normal 400 12px/18px 宋体;position:fixed;}\
  199. #ge_u>span{background:white;color:blue;border-radius:3px;border:1px solid #c0c0c0;padding:2px;cursor:pointer;}\
  200. #ge_u>div{position:relative;margin-top:3px;}\
  201. #ge_u>div>*{position:absolute;}\
  202. .ge_u{background:white;border:1px solid silver;box-shadow:5px 5px 7px #333;}\
  203. .ge_u{width:120px;max-height:400px;overflow-x:hidden;overflow-y:auto;}\
  204. .ge_u>li{position:relative;display:block;padding:2px 20px 4px 6px;}\
  205. .ge_u>li:hover{background:lightgray;}\
  206. .ge_u a{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}\
  207. .ge_u span{position:absolute;top:0;right:0;color:white;background:#77f;border-radius:3px;margin:2px;cursor:pointer;padding:2px;}\
  208. .ge_u span:hover{background:red;}\
  209. .ge_sym{display:inline-block;width:7px;height:7px;border:1px solid #c0c0c0;border-radius:4px;margin-left:3px;}\
  210. .ge_sym.ge_pin{background:#c0c0c0;}\
  211. .ge_opt{padding:20px;border-radius:5px;}\
  212. .ge_opt fieldset{border:1px solid silver;border-radius:5px;padding:5px;}\
  213. .ge_opt textarea{min-height:100px;width:100%;}\
  214. ');
  215. gu=document.createElement('div');gu.id='ge_u';
  216. gu.innerHTML='<span>马甲<span class=ge_sym></span></span><div><ul class="ge_u ge_h"></ul></div>';
  217. gu.style.display=getValue('float','');
  218. ul=gu.querySelector('ul');ul.onclick=userManage;
  219. symbol=gu.firstChild.lastChild;
  220. gu.pin=!!getValue('ge_pin');pinUpdate();
  221. symbol.onclick=function(){setValue('ge_pin',gu.pin=!gu.pin);pin();};
  222. gu.onmouseover=function(e){
  223. if(this.contains(e.relatedTarget)) return;
  224. ul.classList.remove('ge_h');
  225. if(gu.offsetLeft+gu.firstChild.offsetLeft+ul.offsetWidth<=document.body.offsetWidth) ul.style.pixelLeft=0;
  226. else ul.style.pixelLeft=document.body.offsetWidth-gu.offsetLeft-gu.firstChild.offsetLeft-ul.offsetWidth;
  227. };gu.onmouseout=function(e){if(!this.contains(e.relatedTarget)) ul.classList.add('ge_h');};
  228. var d=getValue('ge_users_loc',{});if(typeof d=='string') d=JSON.parse(d);
  229. document.body.appendChild(gu);locate(d);gu.moving=false;
  230. gu.firstChild.onmousedown=function(e){
  231. e.preventDefault();e.stopPropagation();
  232. if(e.target!=gu.firstChild||gu.moving) return;gu.moving=true;
  233. initLoc();
  234. gu.x=e.pageX;
  235. gu.y=e.pageY;
  236. document.addEventListener('mousemove',mousemove,false);
  237. };
  238. gu.onmouseup=function(e){
  239. if(!gu.moving) return;gu.moving=false;
  240. e.preventDefault();e.stopPropagation();
  241. document.removeEventListener('mousemove',mousemove,false);
  242. saveLoc();
  243. };
  244. initMenu();
  245. popup=document.createElement('div');
  246. popup.className='ge_popup ge_opt';
  247. popup.innerHTML='\
  248. <h3>设置 - 百度马甲切换脚本</h3>\
  249. <fieldset><legend>马甲数据 <button id=gu_import>导入</button> <button id=gu_export>导出</button> \
  250. <a title="复制数据到以下文本框然后点击导入即可导入数据。\n点击导出后复制数据文本即可用于导入。">(?)</a></legend>\
  251. <textarea id=gu_data></textarea></fieldset>\
  252. <p align=right><button id=gu_close>关闭</button></p>\
  253. ';
  254. document.body.appendChild(popup);
  255. popup.addEventListener('click',function(e){e.stopPropagation();},false);
  256. var t=popup.querySelector('#gu_data');
  257. t.onclick=function(){this.select();};
  258. popup.querySelector('#gu_import').onclick=function(o){
  259. try{o=JSON.parse(t.value);}catch(e){o=null;}
  260. if(o&&typeof o=='object') {
  261. for(var i in o) users[i]=o[i];
  262. saveUsers();initMenu();alert('导入成功!');
  263. } else alert('导入失败!');
  264. };
  265. popup.querySelector('#gu_export').onclick=function(){t.value=JSON.stringify(users);};
  266. popup.querySelector('#gu_close').addEventListener('click',function(){popup.style.display='';},false);
  267. }
  268. function initMenu(){
  269. d=[];
  270. if(users) {
  271. d.push('<li><a href=#>未登录(不可用)状态</a></li>');
  272. for(var i in users) {
  273. if(!i) {delete users[i];continue;}
  274. d.push('<li><a href=#>'+i.replace(/&/g,'&amp;').replace(/</g,'&lt;')+'</a><span>删</span></li>');
  275. }
  276. } else
  277. d.push('<li title="请添加马甲。" style="color:gray">未检测到Cookie</li>');
  278. d.push('<li><a href=#>添加马甲</a></li>');
  279. ul.innerHTML=d.join('');
  280. }
  281. function showOptions(){
  282. popup.style.display='block';
  283. popup.style.top=(innerHeight-popup.offsetHeight)/2+'px';
  284. popup.style.left=(innerWidth-popup.offsetWidth)/2+'px';
  285. }
  286. var User_Agent='Most handsome in the world',
  287. url_login='http://wappass.baidu.com/passport/login',
  288. menu,gu,ul,symbol,options,users,popup;
  289. if(window.top===window&&document.head) init();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址