-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
30 lines (28 loc) · 1011 Bytes
/
background.js
File metadata and controls
30 lines (28 loc) · 1011 Bytes
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
/*INFO
This script will check if the user is watching an article of the web page eirinika.gr
Inputs: tabId,tab
Outputs:
*/
chrome.tabs.onUpdated.addListener((tabId, tab) => {
if(tab.url && tab.url.includes("https://www.eirinika.gr/article")){
console.log(urlParameters);
const queryParameters = tab.url.split("article")[1];
const urlParameters = new URLSearchParams(queryParameters);
// Regular expression to match the number in the URL
var regex = /\/(\d+)\/[^/]*$/;
var match = tab.url.match(regex);
var articleName = new Date().getUTCMilliseconds();
// Check if a match is found and get the number
if (match && match[1]) {
var number = match[1];
console.log(`Article number is ${number}`); // Output: 259010
articleName = number
} else {
console.log("Number not found in the URL.");
}
chrome.tabs.sendMessage(tabId,{
type:"NEW",
articleId: articleName
})
}
});