Skip to content

Commit

Permalink
1.9.1
Browse files Browse the repository at this point in the history
- Reduce the use of alerts for a smoother user experience.  
- Ensure user-defined rules are preserved during extension updates.
  • Loading branch information
u-Sir authored Jan 1, 2025
1 parent ac915e1 commit ffc9705
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 40 deletions.
3 changes: 2 additions & 1 deletion chromium/background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
chrome.runtime.onInstalled.addListener(() => {
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason !== "install") return;
chrome.declarativeNetRequest.getDynamicRules((rules) => {
// Map the existing rule IDs
const ruleIds = rules.map((rule) => rule.id);
Expand Down
14 changes: 14 additions & 0 deletions chromium/custom_page/custom_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,20 @@
</g>
</svg></button>
</div>
<div id="addContainer" style="display: none;">

<label>
<input id="addURLs" type="text" style="width: 500px;" placeholder="example.com;https://www.example2.com" />
</label>
<button id="saveAddButton"></button>
</div>
<div id="uaContainer" style="display: none;">

<label>
<input id="uaRules" type="text" style="width: 500px;" placeholder="*example.com;*.example2.com/*" />
</label>
<button id="saveUAButton"></button>
</div>
<div id="settingsContainer" style="display: none;">

<label>
Expand Down
92 changes: 75 additions & 17 deletions chromium/custom_page/custom_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ const modeButton = document.getElementById("modeButton");
const rotateButton = document.getElementById("rotateButton");
const settingsContainer = document.getElementById("settingsContainer");
const editContainer = document.getElementById("editContainer");
const addContainer = document.getElementById("addContainer");
const uaContainer = document.getElementById("uaContainer");
const iframeWidthInput = document.getElementById("iframeWidth");
const iframeHeightInput = document.getElementById("iframeHeight");
const oneUrlsInput = document.getElementById("oneUrls");
const twoUrlsInput = document.getElementById("twoUrls");
const threeUrlsInput = document.getElementById("threeUrls");
const fourUrlsInput = document.getElementById("fourUrls");
const iframeGapInput = document.getElementById("iframeGap");
const addURLsInput = document.getElementById("addURLs");
const uaRulesInput = document.getElementById("uaRules");
const saveSettingsButton = document.getElementById("saveSettingsButton");
const saveEditButton = document.getElementById("saveEditButton");
const saveAddButton = document.getElementById("saveAddButton");
const saveUAButton = document.getElementById("saveUAButton");

let iframeWidth = 375; // Default width
let iframeHeight = 667; // Default height
Expand Down Expand Up @@ -438,7 +444,7 @@ function createIframe(url) {

chrome.storage.local.set({ size: data.size });
} else {
alert("Invalid input. Please enter the size in the format 'widthxheight' (e.g., '600x800').");
alert("×");
}
}
});
Expand Down Expand Up @@ -491,16 +497,6 @@ function createIframe(url) {
});
}




// Add new iframe URLs (supporting multiple URLs separated by semicolons)
addButton.addEventListener("click", () => {
hideSettings();
let urls = prompt("URLs: example.com;https://www.example2.com");
addIframe(urls);
});

function addIframe(urls) {

if (urls) {
Expand All @@ -525,6 +521,10 @@ settingsButton.addEventListener("click", () => {

const editContainer = document.getElementById("editContainer");
editContainer.style.display = "none";
const addContainer = document.getElementById("addContainer");
addContainer.style.display = "none";
const uaContainer = document.getElementById("uaContainer");
uaContainer.style.display = "none";

chrome.storage.local.get("iframeSettings", (data) => {
const settings = data.iframeSettings || { width: 375, height: 667, gap: 20 };
Expand Down Expand Up @@ -684,8 +684,14 @@ saveEditButton.addEventListener("click", () => {

// Edit all URLs settings
editAllButton.addEventListener("click", async () => {

const settingsContainer = document.getElementById("settingsContainer");
settingsContainer.style.display = "none";
const addContainer = document.getElementById("addContainer");
addContainer.style.display = "none";
const uaContainer = document.getElementById("uaContainer");
uaContainer.style.display = "none";

chrome.storage.local.get("group", (data) => {
const group = data.group || { Star: '', Sailing: '', Flower: '', Coffee: '' };
const placeholder = "example.com;https://www.example2.com";
Expand Down Expand Up @@ -763,14 +769,48 @@ function hideSettings() {
settingsContainer.style.display = "none";
const editContainer = document.getElementById("editContainer");
editContainer.style.display = "none";
const addContainer = document.getElementById("addContainer");
addContainer.style.display = "none";
const uaContainer = document.getElementById("uaContainer");
uaContainer.style.display = "none";
}

pcUAButton.addEventListener("click", () => {
addButton.addEventListener("click", () => {


const settingsContainer = document.getElementById("settingsContainer");
settingsContainer.style.display = "none";
const editContainer = document.getElementById("editContainer");
editContainer.style.display = "none";
const uaContainer = document.getElementById("uaContainer");
uaContainer.style.display = "none";

// Show prompt with current URLs
addContainer.style.display =
addContainer.style.display === "none" ? "flex" : "none";
addContainer.style.justifyContent = "center";
});

// Add new iframe URLs (supporting multiple URLs separated by semicolons)
saveAddButton.addEventListener("click", () => {
hideSettings();
const urls = addURLsInput.value;
addIframe(urls);
addURLsInput.value = "";
});

pcUAButton.addEventListener("click", () => {

const settingsContainer = document.getElementById("settingsContainer");
settingsContainer.style.display = "none";
const editContainer = document.getElementById("editContainer");
editContainer.style.display = "none";
const addContainer = document.getElementById("addContainer");
addContainer.style.display = "none";

chrome.declarativeNetRequest.getDynamicRules((rules) => {
const pcUAValue =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";
let maxRuleId = rules.length > 0 ? Math.max(...rules.map((rule) => rule.id)) : 0;

// Filter existing rules that modify User-Agent to PC UA
const uaRules = rules.filter((rule) =>
Expand All @@ -783,11 +823,30 @@ pcUAButton.addEventListener("click", () => {
const urlFilters = uaRules.map((rule) => rule.condition.urlFilter).join(";");

// Show prompt with current URLs
const input = prompt(
"PC User-Agent URLs: \n*.example.com;https://www.example2.com/path/*",
urlFilters || ""
uaContainer.style.display =
uaContainer.style.display === "none" ? "flex" : "none";
uaContainer.style.justifyContent = "center";
uaRulesInput.value = urlFilters;

});
});

saveUAButton.addEventListener("click", () => {

chrome.declarativeNetRequest.getDynamicRules((rules) => {
const pcUAValue =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";
let maxRuleId = rules.length > 0 ? Math.max(...rules.map((rule) => rule.id)) : 0;
// Filter existing rules that modify User-Agent to PC UA
const uaRules = rules.filter((rule) =>
rule.action?.requestHeaders?.some(
(header) => header.header === "User-Agent" && header.value === pcUAValue
)
);

hideSettings();
const input = uaRulesInput.value;

if (input !== null) {
const newUrls = input
.split(";")
Expand Down Expand Up @@ -858,7 +917,6 @@ pcUAButton.addEventListener("click", () => {
});
});


rotateButton.addEventListener("click", async () => {
hideSettings();
// Retrieve the current list of URLs from chrome.storage.local
Expand Down
2 changes: 1 addition & 1 deletion chromium/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Tabless",
"version": "1.9",
"version": "1.9.1",
"permissions": [
"declarativeNetRequest",
"storage"
Expand Down
3 changes: 2 additions & 1 deletion firefox/background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
chrome.runtime.onInstalled.addListener(() => {
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason !== "install") return;
chrome.declarativeNetRequest.getDynamicRules((rules) => {
// Map the existing rule IDs
const ruleIds = rules.map((rule) => rule.id);
Expand Down
18 changes: 16 additions & 2 deletions firefox/custom_page/custom_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</g>
</g>
</svg> </a></button>
<button id="split">
<button id="split" style="cursor: unset;">
<svg width="20px" height="20px" viewBox="0 -9.5 21 21" version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" fill="#D7716E" transform="rotate(90)">
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
Expand Down Expand Up @@ -194,7 +194,7 @@
</g>

</svg></button>
<button id="split-end" style="display: none;">
<button id="split-end" style="display: none; cursor: unset;">
<svg width="20px" height="20px" viewBox="0 -9.5 21 21" version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" fill="#D7716E" transform="rotate(90)">
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
Expand Down Expand Up @@ -287,6 +287,20 @@
</g>
</svg></button>
</div>
<div id="addContainer" style="display: none;">

<label>
<input id="addURLs" type="text" style="width: 500px;" placeholder="example.com;https://www.example2.com" />
</label>
<button id="saveAddButton"></button>
</div>
<div id="uaContainer" style="display: none;">

<label>
<input id="uaRules" type="text" style="width: 500px;" placeholder="*example.com;*.example2.com/*" />
</label>
<button id="saveUAButton"></button>
</div>
<div id="settingsContainer" style="display: none;">

<label>
Expand Down
Loading

0 comments on commit ffc9705

Please sign in to comment.