-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
114 lines (98 loc) · 4.07 KB
/
content.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
var generator = document.getElementsByName('generator');
var appendText = "/language/en-GB/en-GB.xml";
var _loadDoc;
if(generator.length != 0){
var content = generator[0].getAttribute('content');
var links = document.getElementsByTagName('a');
var _Isadminitrator =false;
var _cms = content.split(" ")[0];
if(_cms == "Joomla!" && _Isadminitrator == false){
loadDoc();
setTimeout(function(){
//code to send message to open notification.
chrome.runtime.sendMessage({type: "notification" , version: _loadDoc, options: {
type: "basic",
iconUrl: "logo.png",
title: window.location.origin,
message: "Joomla "+_loadDoc
}});
},1000);
// Loop all the <a> tag then pass to the IsAdministrator function to check
for(var i = 0; i< links.length; i++){
if(IsAdministrator(links[i].href)){
_Isadminitrator = true;
}
}
/* Function run when clicked on browser Action Gotmessgae is callback function*/
chrome.runtime.onMessage.addListener(Gotmessgae);
// Callback Function when recive the message from the background script then perform the task
function Gotmessgae(messgae,sender,SendResponse){
if(_cms == "Joomla!" && _Isadminitrator == false){
window.open(window.location.origin+"/administrator");
}else if(_cms == "Joomla!" && _Isadminitrator == true){
window.open(window.location.origin);
}
}
//Function check current page is IsAdministrator for joomla
//Params Sting|str
function IsAdministrator(str){
var admin = str.split("/");
for(var i = 0; i< admin.length; i++){
//console.log(admin[i]);
if(admin[i] == "administrator"){
return true;
break;
}
}
}
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var xmlDoc = this.responseXML;
var version = xmlDoc.getElementsByTagName("version")[0].childNodes[0].nodeValue;
_loadDoc = version;
}
};
xhttp.open("GET", window.location.origin+appendText, true);
xhttp.send();
}
}else if(_cms == "WordPress"){
_version = content.split(" ")[1];
//code to send message to open notification.
chrome.runtime.sendMessage({type: "wordpress" , version: _version, options: {
type: "basic",
iconUrl: "logo.png",
title: window.location.origin,
message: "Wordpress "+_version
}});
/* Function run when clicked on browser Action Gotmessgae is callback function*/
chrome.runtime.onMessage.addListener(Gotmessgae);
// Callback Function when recive the message from the background script then perform the task
function Gotmessgae(messgae,sender,SendResponse){
if(_cms == "WordPress" && _Isadminitrator == false){
window.open(window.location.origin+"/wp-admin");
}else if(_cms == "WordPress" && _Isadminitrator == true){
window.open(window.location.origin);
}
}
// Loop all the <a> tag then pass to the IsAdministrator function to check
for(var i = 0; i< links.length; i++){
if(IsWpAdmin(links[i].href)){
_Isadminitrator = true;
}
}
// Function check current page is IsWpadmin for joomla
// Params Sting|str
function IsWpAdmin(str){
var admin = str.split("/");
for(var i = 0; i< admin.length; i++){
//console.log(admin[i]);
if(admin[i] == "wp-admin"){
return true;
break;
}
}
}
}
}