-
Notifications
You must be signed in to change notification settings - Fork 9
/
popup.js
69 lines (62 loc) · 2.12 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function setDOMInfo(info) {
if (info != null)
document.getElementById('content').innerHTML = info;
var dds = document.getElementsByTagName("button");
for (var i = 0, l = dds.length; l > i; i++)
dds[i].onclick = apply_event(dds[i]);
}
// Once the DOM is ready...
window.addEventListener('DOMContentLoaded', function () {
// ...query for the active tab...
chrome.tabs.query({
active: true,
currentWindow: true
}, function (tabs) {
// ...and send a request for the DOM info...
chrome.tabs.sendMessage(
tabs[0].id,
{from: 'popup', subject: 'DOMInfo'},
// ...also specifying a callback to be called
// from the receiving end (content script)
setDOMInfo);
});
});
var apply_event = function(dd) {
return function() {
chrome.tabs.query({
active: true,
currentWindow: true
}, function (tabs) {
// ...and send a request for the DOM info...
chrome.tabs.sendMessage(
tabs[0].id,
{from: 'popup', subject: dd.className, to_apply:dd.id},
// ...also specifying a callback to be called
// from the receiving end (content script)
setDOMInfo);
});
}
};
var tmp;
function cookieinfo(){
chrome.cookies.get({name:"PREF", url:"https://www.youtube.com"},function (cookie){
var YT_COOKIE = cookie;
tmp = YT_COOKIE;
console.log(cookie);
modified_val = YT_COOKIE["value"]
index = modified_val.indexOf('4100') + 4
console.log(YT_COOKIE["value"])
modified_val = modified_val.substr(0, index) + '8' + modified_val.substr(index + 1);
console.log(modified_val, "old:", YT_COOKIE["value"])
if (YT_COOKIE["value"][index] == '4') {
chrome.cookies.set({ url: "https://www.youtube.com", name: "PREF", value: modified_val, expirationDate: YT_COOKIE["expirationDate"]});
console.log("Done");
chrome.tabs.getSelected(null, function(tab) {
var code = 'window.location.reload();';
chrome.tabs.executeScript(tab.id, {code: code});
});
}
});
}
cookieinfo()
// window.onload=cookieinfo;