Greasy Fork

Greasy Fork is available in English.

Baidu Multiuser

百度马甲切换

当前为 2014-05-16 提交的版本,查看 最新版本

// ==UserScript==
// @name	Baidu Multiuser
// @namespace	http://gera2ld.blog.163.com/
// @author	Gerald <[email protected]>
// @icon	http://s.gravatar.com/avatar/a0ad718d86d21262ccd6ff271ece08a3?s=80
// @version	1.4.3
// @description	百度马甲切换
// @homepage	http://userscripts.org/scripts/show/160577
// @match	*://*.baidu.com/*
// @include	*.baidu.com/*
// @exclude http://developer.baidu.com/*
// @exclude http://web.im.baidu.com/*
// @require	http://userscripts.org/scripts/source/186749.user.js
// @grant	GM_getValue
// @grant	GM_setValue
// @grant	GM_openInTab
// @grant	GM_registerMenuCommand
// ==/UserScript==
function e(e,t){var o=GM_getValue(e,"");return o&&"string"==typeof o&&(o=JSON.parse(o)),o||t}function t(e,t){GM_setValue(e,JSON.stringify(t))}function o(e,t){var o=new Date;e?o.setTime(16094e8):e="",document.cookie="BDUSS="+e+";domain=baidu.com;path=/;expires="+o.toGMTString(),"function"==typeof t?t():"string"==typeof t?location.replace(t):location.reload()}function i(){v.right=v._right=v.parentNode.offsetWidth-v.offsetWidth-v.offsetLeft,v.top=v._top=v.offsetTop}function n(){t("ge_users",k)}function a(){t("ge_users_loc",{right:v.right,top:v.top})}function s(e,t,i){e.preventDefault(),i=e.target,e=i.parentNode,t=e.parentNode,"A"==i.tagName?e==t.firstChild?o():e==t.lastChild?GM_openInTab("http://wappass.baidu.com/?login&u=http://www.baidu.com"):o(k[i.innerText||i.textContent]):"SPAN"==i.tagName&&(i=i.previousSibling,delete k[i.innerText||i.textContent],setTimeout(n,0),t.removeChild(e))}function l(e){e&&(v.right=e&&!isNaN(e.right)?e.right:100,v.top=e&&!isNaN(e.top)?e.top:100),v.style.right=v.right+"px",v.style.top=v.top+"px"}function r(e){e.preventDefault(),e.stopPropagation();var t={right:v._right+v.x-e.pageX,top:v._top+e.pageY-v.y};l(t)}function u(){b.innerHTML=v.pin?"●":"○",b.setAttribute("title",v.pin?"固定在页面上":"固定在屏幕上"),v.style.position=v.pin?"absolute":""}function p(){i(),v.pin?v.top+=window.pageYOffset:v.top-=window.pageYOffset,u(),l(),a()}function c(){utils.addStyle("#ge_u{display:block;padding:10px;text-align:left;}#ge_u .ge_h{display:none;}#ge_u{z-index:10006;font:normal normal 400 12px/18px 宋体;position:fixed;}#ge_u>span{background:white;color:blue;border-radius:3px;border:1px solid #c0c0c0;padding:2px;cursor:pointer;}#ge_u>div{position:relative;margin-top:3px;}#ge_u>div>*{position:absolute;}.ge_u{background:white;border:1px solid silver;box-shadow:5px 5px 7px #333;}.ge_u{width:120px;max-height:400px;overflow-x:hidden;overflow-y:auto;}.ge_u>li{position:relative;display:block;padding:2px 20px 4px 6px;}.ge_u>li:hover{background:lightgray;}.ge_u a{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}.ge_u span{position:absolute;top:0;right:0;color:white;background:#77f;border-radius:3px;margin:2px;cursor:pointer;padding:2px;}"),v=document.createElement("div"),v.id="ge_u",v.innerHTML='<span>马甲<span></span></span><div><ul class="ge_u ge_h"></ul></div>',v.style.display=e("float",""),x=v.querySelector("ul"),x.onclick=s,b=v.firstChild.lastChild,v.pin=!!e("ge_pin"),u(),b.onclick=function(){t("ge_pin",v.pin=!v.pin),p()},v.onmouseover=function(e){this.contains(e.relatedTarget)||(x.classList.remove("ge_h"),x.style.pixelLeft=v.offsetLeft+v.firstChild.offsetLeft+x.offsetWidth<=document.body.offsetWidth?0:document.body.offsetWidth-v.offsetLeft-v.firstChild.offsetLeft-x.offsetWidth)},v.onmouseout=function(e){this.contains(e.relatedTarget)||x.classList.add("ge_h")};var o=e("ge_users_loc",{});"string"==typeof o&&(o=JSON.parse(o)),document.body.appendChild(v),l(o),v.moving=!1,v.firstChild.onmousedown=function(e){e.preventDefault(),e.stopPropagation(),e.target!=v.firstChild||v.moving||(v.moving=!0,i(),v.x=e.pageX,v.y=e.pageY,document.addEventListener("mousemove",r,!1))},v.onmouseup=function(e){v.moving&&(v.moving=!1,e.preventDefault(),e.stopPropagation(),document.removeEventListener("mousemove",r,!1),a())},f()}function f(){if(d=[],k){d.push("<li><a href=#>未登录状态</a></li>");for(var e in k)e?d.push("<li><a href=#>"+e.replace(/&/g,"&amp;").replace(/</g,"&lt;")+"</a><span>删</span></li>"):delete k[e]}else d.push('<li title="未检测到Cookie,请任意添加一个马甲或自行去除对应Cookie的HttpOnly属性。" style="color:gray">未检测到Cookie</li>');d.push("<li><a href=#>添加马甲</a></li>"),x.innerHTML=d.join("")}function g(){utils.popup.show({html:x.innerHTML,className:"ge_u",init:function(e){x.style.display="none",e.onclick=s},dispose:function(e){x.style.display="",e.onclick=null,f()}})}function h(){utils.popup.show({html:"<h3>设置 - 百度马甲切换脚本</h3><label><input type=checkbox id=gu_showfloat>显示悬浮图标</label><br><label>切换马甲快捷键:"+utils.getLink("common",{title:"帮助",html:"(?)"})+'<input id=gu_shortcut></label><br><fieldset><legend>马甲数据 <button id=gu_import>导入</button> <button id=gu_export>导出</button> <a title="复制数据到以下文本框然后点击导入即可导入数据。\n点击导出后复制数据文本即可用于导入。">(?)</a></legend><textarea id=gu_data></textarea></fieldset>',className:"ge_opt",init:function(o){var i=o.querySelector("#gu_showfloat");i.checked="none"!=e("float"),i.onchange=function(){v.style.display=this.checked?"":"none",t("float",v.style.display)},i=o.querySelector("#gu_shortcut"),i.value=S,i.onchange=function(){S&&utils.shortcut(S),S=this.value,m(),t("shortcut",S)},i=o.querySelector("#gu_data"),i.onclick=function(){this.select()},o.querySelector("#gu_import").onclick=function(e){try{e=JSON.parse(i.value)}catch(t){e=null}if(e&&"object"==typeof e){for(var o in e)k[o]=e[o];n(),f(),alert("导入成功!")}else alert("导入失败!")},o.querySelector("#gu_export").onclick=function(){i.value=JSON.stringify(k)}}})}function m(){S&&utils.shortcut(S,g)}function _(t,o){k=e("ge_users",{}),S=e("shortcut","s-m"),(t=PageData)&&t.user&&t.user.is_login&&t.user.name?t=t.user.name:(t=unsafeWindow.s_session)&&(t=t.username),t&&(o=document.cookie.match(/BDUSS=(.*?)(;|$)/),o?(k[t]=o[1],n()):k=null),GM_registerMenuCommand("百度马甲设置",h),c(),m()}var y,v,x,b,w,k,S;window.top===window&&document.head&&_();