-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpopup.js
35 lines (29 loc) · 1.09 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* Encoding : UTF-8
* Description: chrome拓展 屏蔽百度推广链接
*
* @author @齐士博 <[email protected]>
*
* @link http://weibo.com/shiboooo/
*/
~function(){
var rightSwitchKey = 'right_ad_switch';
document.getElementById("radio").onclick = function () {
var rightSwitch = document.getElementById('radio').checked;
chrome.storage.sync.set({[rightSwitchKey]: rightSwitch ? 1 : 0}, function() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var url = tabs[0].url;
if (url.indexOf('www.baidu.com') !== -1) {
chrome.tabs.update(tabs[0].id, {url: url});
}
else {
document.getElementById('desc-extra').innerHTML = '更新成功,刷新百度搜索结果页即可';
}
});
});
};
chrome.storage.sync.get(rightSwitchKey, function(data) {
var rightSwitch = data[rightSwitchKey];
document.getElementById('radio').checked = ((rightSwitch == 1) ? true : false);
});
}();