-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
119 lines (95 loc) · 3.73 KB
/
background.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright (c) 2011 The Chromium Authors. All rights reserved. (Used their script as a guide to the structure of chrome addons, feels bad to not credit them at all)
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
chrome.runtime.onInstalled.addListener(function () {
chrome.storage.sync.set({ 'number': 1 }, function () { });
setIcon(2);
});
function setIcon(Innumber) {
var nax;
if(Innumber == 1){
nax = 2;} else{
nax = 1;}
chrome.storage.sync.set({ number: nax }, function () { });
chrome.browserAction.setIcon({ path: 'icon' + Innumber + '.png' });
}
function updateIcon() {
chrome.storage.sync.get('number', function(data) {
var current = data.number;
chrome.browserAction.setIcon({path: 'icon' + current + '.png'});
current++;
if (current > 2) {
ParseUrl();
current = 1;
}
chrome.storage.sync.set({number: current}, function() {
console.log('The number is set to ' + current);
});
});
};
chrome.browserAction.onClicked.addListener(updateIcon);
function Addlisten() {
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (changeInfo.status == 'complete' && tab.active) {
chrome.storage.sync.get('number', function (data) {
var current = data.number;
if (current == 1) {
//alert("working");
ParseUrl();
} else {
//alert("not working");
}
// do your things
});
}
});
}
Addlisten();
function ParseUrl() {
//alert("called");
chrome.tabs.query({
active: true,
lastFocusedWindow: true
}, function (tabs) {
// and use that tab to fill in out title and url
var tab = tabs[0];
if (tab.url.includes("xn--", 0)) {
alert("URL includes PUNYcode style address, Be careful it is the right Webpage! "+ tab.url);
}
var upto;
var slashcount = 0;
for (x = 0; x < tab.url.length; x++){
if(tab.charAt(x) == "/"){
slashcount = slashcount +1;
}
if(slashcount == 3){
upto =x;
x=tab.url.length;
}
}
var x = 0;
for (x = 0; x < upto; x++){
if(tab.url.charCodeAt(x) > 127){
alert("URL contains non-alphabetic character "+tab.charAt(x) + " Be careful it is the right Webpage!");
}
for(x = 0; x<upto;x++){
if(tab.url.charAt(x)== "%"){
//if 0123456789ABCDEFG
if((tab.url.charCodeAt(x+1) >= 48 && tab.url.charCodeAt(x+1) <= 57) || tab.url.charCodeAt(x+1) >= 65 && tab.url.charCodeAt(x+1) <= 70){
if((tab.url.charCodeAt(x+1) >= 48 && tab.url.charCodeAt(x+1) <= 57) || tab.url.charCodeAt(x+1) >= 65 && tab.url.charCodeAt(x+1) <= 70){
var HexString = (tab.url.charAt(x+1) + tab.url.charAt(x+2));
var DecNumber = parseInt(HexString, 16);
if(DecNumber > 127){
var ActualChar;
ActualChar = String.fromCharCode(DecNumber);
alert("URL contains non-alphabetic character sequence '"+ ActualChar + "' Be careful it is the right Webpage!");
x=tab.url.length;
}
}
}
}
}
}
});
}