class PopupService { async SendMessage(eventName, callback) { chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) { chrome.tabs.sendMessage(tabs[0].id, { event: eventName }, callback); }); } async GetHyperlinks() { const a = this; const baseUrl = await a.GetLocation(); return new Promise(function(resolve) { a.SendMessage("GetNodes", async function(payload) { // let result = { // items: payload.copy(), // totalCount: payload.length, // distinctCount: 0 // }; // result.items = result.items.orderBy("innerText"); // result.items = result.items.distinct(); // result.distinctCount = result.items.length; // Populate occurrence counter // for (let i=0; i JSON.stringify(item) === JSON.stringify(result.items[i])).length; // } // resolve(result); // console.log(payload); resolve(payload.copy()); }); }); } async GetLocation() { const a = this; return new Promise(function(resolve) { a.SendMessage("GetLocation", function(payload) { resolve(payload); }); }); } } class ContentService { GenerateCheckBox(num, label, checked) { let html = ""; html += "
"; html += ""; html += ""; html += "
"; return html; } GenerateCols(...args) { let html = ""; for (let i=0; i" + args[i] + ""; } return html; } GenerateRow(...args) { const a = this; if (args.length === 1) { if (Object.getDataType(args[0]) == "array") { args = args[0]; } } let result = ""; for (let i=0; i" + result + ""; } GenerateRowCell(value) { return ""; } } class AContentService extends ContentService { ContainerPanel = null; Panel1 = null; Button1 = null; Button2 = null; Label1 = null; Table1 = null; #PopupService = null; #TableLabel = "Results"; constructor(popupService) { super(); this.#PopupService = popupService; } InitialiseComponents(){ const a = this; a.ContainerPanel = document.getElementById("nav-hyperlinks"); a.Panel1 = a.ContainerPanel.querySelectorAll("div[role='options']")[0]; a.Button1 = a.ContainerPanel.querySelectorAll("button")[0]; a.Button2 = a.ContainerPanel.querySelectorAll("button")[1]; a.Label1 = a.ContainerPanel.querySelectorAll("span[role='table-heading']")[0]; a.Table1 = a.ContainerPanel.querySelectorAll("table")[0]; a.Clear(); let col1 = ""; col1 += a.GenerateCheckBox(1, "Show Anchor as HTML", false); col1 += a.GenerateCheckBox(3, "Sort By Anchor Text", true); col1 += a.GenerateCheckBox(2, "Trim Anchor Text", true); col1 += a.GenerateCheckBox(4, "Resolve Relative URL", false); col1 += a.GenerateCheckBox(12, "Hide External Links", true); let col2 = ""; col2 += a.GenerateCheckBox(5, "Hide Duplicates", true); col2 += a.GenerateCheckBox(14, "Hide Blank Anchors", true); col2 += a.GenerateCheckBox(15, "Hide Blank Links", true); col2 += a.GenerateCheckBox(11, "Hide Fragments", true); col2 += a.GenerateCheckBox(13, "Hide Mailto/Tel", true); let col3 = ""; col3 += a.GenerateCheckBox(6, "Show Title", true); col3 += a.GenerateCheckBox(7, "Show Target", false); col3 += a.GenerateCheckBox(8, "Show Rel", false); col3 += a.GenerateCheckBox(9, "Show Type", false); col3 += a.GenerateCheckBox(10, "Show Occurrence", false); let html = a.GenerateCols(col1, col2, col3); a.#writeOptionsPanel(html); a.Button1.addEventListener('click', async function (e) { a.Button1.disabled = true; await a.Search(); a.Button1.disabled = false; }); } Clear() { const a = this; a.#writeOptionsPanel(""); a.#clearTable(); } async Search() { const a = this; const thead = a.Table1.querySelectorAll("thead")[0]; const tbody = a.Table1.querySelectorAll("tbody")[0]; a.#clearTable(); // Write thead thead.innerHTML = "" + a.#generateTHeader() + ""; const result = await a.#PopupService.GetHyperlinks(); const totalCount = result.length; a.Label1.innerText = a.#TableLabel + " (" + totalCount + ")"; const newResults = await a.#filterSearch(result.copy()); if (newResults.length != totalCount) { a.Label1.innerText = a.#TableLabel + " (" + newResults.length + "/" + totalCount + ")"; } for (let i=0; i JSON.stringify(item) === JSON.stringify(result[i])).length; occurrenceCache.push(occurrence); } // Update result with occurrence for (let i=0; i"; } } return html; } #getCheckBox(num) { const a = this; if (a.Panel1 == null) { return false; } const result = a.Panel1.querySelectorAll("input[id='checkbox" + num + "']"); if (result.length <= 0) { return false; } return result[0].checked; } #writeOptionsPanel(htmlContent) { const a = this; if (a.Panel1 == null) { return; } a.Panel1.innerHTML = htmlContent; } } const popupService = new PopupService(); const aContentService = new AContentService(popupService); document.addEventListener("DOMContentLoaded", async function(event) { aContentService.InitialiseComponents(); // aContentService.Button1.addEventListener('click', async function (e) { // const body = aContentService.Table1.querySelectorAll("tbody")[0]; // body.innerHTML = ""; // const result = await popupService.GetHyperlinks(); // for (let i=0; i { // Print response on popup.html // var msg = document.createElement("h3"); // msg.innerHTML = "H1:" + response; // document.getElementById("container”).appendChild(msg); // memoBox1.innerHTML = response; // alert("!"); // }); }); */ // document.getElementsByTagName("a").array.forEach(e => { // memoBox1.innerHTML += e.href + "\n"; // }); // var switch1 = document.getElementById("switch1"); // var switch2 = document.getElementById("switch2"); // var switch3 = document.getElementById("switch3"); // var switch4 = document.getElementById("switch4"); // var switch5 = document.getElementById("switch5"); // var switch6 = document.getElementById("switch6"); // // read local storage // chrome.storage.local.get(['switch1'], function(result) { // switch1.checked = result.switch1; // }); // chrome.storage.local.get(['switch2'], function(result) { // switch2.checked = result.switch2; // }); // chrome.storage.local.get(['switch3'], function(result) { // switch3.checked = result.switch3; // }); // chrome.storage.local.get(['switch4'], function(result) { // switch4.checked = result.switch4; // }); // chrome.storage.local.get(['switch5'], function(result) { // switch5.checked = result.switch5; // }); // chrome.storage.local.get(['switch6'], function(result) { // switch6.checked = result.switch6; // }); // // set values // switch1.addEventListener('change', function (e) { // chrome.storage.local.set({ switch1: e.target.checked}, function() { // // do nothing // }); // }); // switch2.addEventListener('change', function (e) { // chrome.storage.local.set({ switch2: e.target.checked}, function() { // // do nothing // }); // }); // switch3.addEventListener('change', function (e) { // chrome.storage.local.set({ switch3: e.target.checked}, function() { // // do nothing // }); // }); // switch4.addEventListener('change', function (e) { // chrome.storage.local.set({ switch4: e.target.checked}, function() { // // do nothing // }); // }); // switch5.addEventListener('change', function (e) { // chrome.storage.local.set({ switch5: e.target.checked}, function() { // // do nothing // }); // }); // switch6.addEventListener('change', function (e) { // chrome.storage.local.set({ switch6: e.target.checked}, function() { // // do nothing // }); // }); });