56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
class MessagingService {
|
|
|
|
async GetNodes(sender, callback) {
|
|
const a = this;
|
|
const nodes = await document.body.getElementsByTagName("a");
|
|
let result = [];
|
|
|
|
for (let i=0; i<nodes.length; i++) {
|
|
result.push({
|
|
innerText: nodes[i].innerText ?? "",
|
|
innerHTML: nodes[i].innerHTML ?? "",
|
|
href: (nodes[i].getAttribute("href") ?? "").trim(),
|
|
title: (nodes[i].getAttribute("title") ?? "").trim(),
|
|
target: nodes[i].getAttribute("target") ?? "",
|
|
rel: nodes[i].getAttribute("rel") ?? "",
|
|
type: nodes[i].getAttribute("type") ?? "",
|
|
occurrence: 1
|
|
});
|
|
}
|
|
|
|
// for (let i=0; i<result.length; i++) {
|
|
// result[i].occurrence = result.filter(item => JSON.stringify(item) === JSON.stringify(result[i])).length;
|
|
// }
|
|
|
|
await callback(result);
|
|
}
|
|
|
|
async GetLocation(sender, callback) {
|
|
callback(document.location.href);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
const messageService = new MessagingService();
|
|
|
|
|
|
chrome.runtime.onMessage.addListener(async function(request, sender, callback) {
|
|
|
|
if (typeof(messageService[request.event]) == "undefined") {
|
|
return;
|
|
}
|
|
|
|
await messageService[request.event](sender, callback);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// var optHideWatchedVideos = new Promise(function(resolve) {
|
|
// chrome.storage.local.get(['switch1'], function(result) {
|
|
// resolve(result.switch1);
|
|
// });
|
|
// });
|