代码很简单:
chrome的插件主要是放在一个文件夹里面 然后在chrome浏览器里面打包就ok了。
这样:
开始看代码:
==
主控代码
manifest.json
{
"name":"a",
"version": "1.0",
"manifest_version": 2,
"description": "1",
"permissions":[
"tabs",
"https://*/*",
"http://*/*"
],
"browser_action":{
"default_icon":"icon.png",
"default_popup":"popup.html"
},
"background": {
"scripts": ["bg.js"],
"persistent": false
}
}
==
bg.js
console.log("background")
chrome.tabs.onUpdated.addListener(function(tabId , info) {
if (info.status == "complete") {
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
var url = tabs[0].url;
console.log(url)
//if(url=="https://www.baidu.com/"){
// chrome.tabs.executeScript(null,{code:'alert("Hello World!")'});
// }http://user.qzone.qq.com/ removeEventListener
//window.addEventListener("scroll", function(){console.log(8)});
// window.οnscrοll=function(){console.log(123)}
if(url.match('user.qzone.qq.com')){
var strjs='var items=document.getElementsByClassName("item");'+
'for(var i=0;i
// chrome.tabs.executeScript(null,{code:' window.οnscrοll=function(){setTimeout( '+strjs+', 3000) }'});
//ok chrome.tabs.executeScript(null,{code:'window.οnscrοll=function(){ console.log(8888);var items=document.getElementsByClassName("item"); console.log(items)}'});
chrome.tabs.executeScript(null,{code:'window.οnscrοll=function(){ console.log(8888);var items=document.getElementsByClassName("item"); for(var i=0;i
//var items=document.getElementsByClassName("item")
//for(var i=0;i
//var s=items[i].innerHTML
//!s.match('赞')||s.match('取消赞')||items[i].click();
// }
//chrome.tabs.executeScript(null,{code:});
}
});
}
});
==
popup.js
document.getElementById("p1").innerHTML="空间点赞"
==
popup.html
空间点赞body {
min-width: 100px;
overflow-x: hidden;
}
img {
margin: 5px;
border: 2px solid black;
vertical-align: middle;
width: 75px;
height: 75px;
}
空间点赞
==
icon.png 就是一个普通的图片
==
打包后的效果是: