chrome贴吧助手插件
manifest.json
{
"background": {
"page": "background.html"
},
"content_scripts": [ {
"js": [ "loadJS.js" ],
"matches": [ "http://tieba.baidu.com/*" ],
"run_at": "document_end"
} ],
"description": "百度贴吧自动签到,自定义表情,阅读魔法书,翻转帖子中图片,设置朋友昵称,自定义背景图,一键换号,大召唤系统,吧务工具扫描广告贴,等等",
"icons": {
"128": "sample-128.png",
"48": "sample-48.png"
},
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCw2V2sSkP7JvAg2ln73cUPdVPiSguLEAs59CpZqayQsn/mE0JoNIX9TwDPNOfPvAjLcYbjfU1sdp8HmZGM7EQ7J2w/XQymxPikEqMZR7NO+trzCJ57+XSvJbYTtuZ8D9dC/3V6LR2dXkrvAduhQQ5XQ64ukfVxii8+3+kb7psM2wIDAQAB",
"manifest_version": 2,
"name": "百度贴吧助手",
"permissions": [ "http://*.baidu.com/*", "https://*.baidu.com/*", "http://*.guzzservices.com/*", "http://*.mofamulu.com/*" ],
"version": "3.0.1"
}
js
function _tieba_load_js_(url) { var domScript = document.createElement('script'); domScript.src = url; domScript.charset = 'gbk'; var body = document.getElementsByTagName('body') ; if(body && body.length > 0){ body[0].appendChild(domScript); } } function _tieba_load_css_(url) { var head=document.getElementsByTagName('head').item(0); if(head){ css=document.createElement('link'); css.href=url; css.rel='stylesheet'; css.type='text/css'; head.appendChild(css); } } function _tieba_insert_unique_div_() { var div = document.createElement('div'); div.id = "fsjfsruwosfmsfjsffsfwddd"; div.setAttribute("style", "display:none;") ; div.setAttribute("pluginversion", "chrome30") ; var body = document.getElementsByTagName('body') ; if(body && body.length > 0){ body[0].appendChild(div); } } var port = chrome.extension.connect(); if(!document.getElementById("fsjfsruwosfmsfjsffsfwddd")){ _tieba_insert_unique_div_() ; _tieba_load_css_("http://tieba.guzzservices.com/s/render.css") ; _tieba_load_js_("http://tieba.guzzservices.com/s/render.js") ; window.addEventListener("message", function(event) { // We only accept messages from ourselves if (event.source != window) return; if (event.data.type && (event.data.type == "tbhp_xhr_req")) { //window.postMessage({type: "tbhp_xhr_req", method: method, url : url, data : data, uniqueId : uniqueId}, "*"); port.postMessage({ method: event.data.method, action: "xhttp", url: event.data.url, data:event.data.data, uniqueId:event.data.uniqueId }); /* chrome.extension.sendMessage({ method: event.data.method, action: "xhttp", url: event.data.url, data:event.data.data, uniqueId:event.data.uniqueId }, function(result) { console.log("loadJS:" + result.xhr.responseText) ; window.postMessage({"type":"tbhp_xhr_back", "uniqueId" : result.uniqueId, "status":result.status, "html":result.xhr.responseText}, "*"); }) ; */ } }, false); port.onMessage.addListener(function(result) { window.postMessage({"type":"tbhp_xhr_back", "uniqueId" : result.uniqueId, "status":result.status, "html":result.html}, "*"); }); }
background.js
/** * Possible parameters for request: * action: "xhttp" for a cross-origin HTTP request * method: Default "GET" * url : required, but not validated * data : data to send in a POST request * * The callback function is called upon completion of the request */ chrome.extension.onMessage.addListener(function(request, sender, callback) { if(request.action == "xhttp") { var method = request.method ? request.method.toUpperCase() : 'GET'; $.ajax({ type: method, url: request.url, dataType:"html", data: request.data, uniqueId : request.uniqueId, complete: function(xhr, ts){ callback({"status": ts, "xhr" : xhr, "uniqueId" : this.uniqueId}) ; } }); return true ; } }); chrome.extension.onConnect.addListener(function(port) { port.onMessage.addListener(function(request) { if(request.action == "xhttp") { var method = request.method ? request.method.toUpperCase() : 'GET'; $.ajax({ type: method, url: request.url, dataType:"html", data: request.data, uniqueId : request.uniqueId, complete: function(xhr, ts){ var text = xhr.responseText ; port.postMessage({action: "xhttp","status": ts, "html" : text, "uniqueId" : this.uniqueId}); } }); } }); });
background.html
<html><head> <meta charset="utf-8" /> <script src="jquery.min.js"></script> <script src="background.js"></script> </head> </body></html>
代码
var tbhp_www_base_url="",tbhp_www_render_loaded=!1; (function(){function e(a){a>=f.length||(tbhp_www_base_url=f[a],g._load_js(tbhp_www_base_url+"/s/real_render.js",function(a,d){a==tbhp_www_base_url+"/s/real_render.js"&&d&&!tbhp_www_render_loaded&&(tbhp_www_render_loaded=!0)}),setTimeout(function(){tbhp_www_render_loaded||e(a+1)},2E3))}var g={_load_js:function(a,c){var d=document.getElementsByTagName("head")[0],b=document.createElement("script");b.src=a;b.type="text/javascript";d.appendChild(b);c&&(b.onload=b.onreadystatechange=function(){!this.readyState|| "complete"==this.readyState||"loaded"==this.readyState?c(a,!0):c(a,!1)})}},f=["http://book.mofamulu.com","http://tieba.guzzservices.com"];e(0)})();
var tbhp_www_base_url = "", tbhp_www_render_loaded = !1; (function() { function e(a) { a >= f.length || (tbhp_www_base_url = f[a], g._load_js(tbhp_www_base_url + "/s/real_render.js", function(a, d) { a == tbhp_www_base_url + "/s/real_render.js" && d && !tbhp_www_render_loaded && (tbhp_www_render_loaded = !0) }), setTimeout(function() { tbhp_www_render_loaded || e(a + 1) }, 2E3)) } var g = { _load_js: function(a, c) { var d = document.getElementsByTagName("head")[0], b = document.createElement("script"); b.src = a; b.type = "text/javascript"; d.appendChild(b); c && (b.onload = b.onreadystatechange = function() { ! this.readyState || "complete" == this.readyState || "loaded" == this.readyState ? c(a, !0) : c(a, !1) }) } }, f = ["http://book.mofamulu.com", "http://tieba.guzzservices.com"]; e(0) })();