-
Notifications
You must be signed in to change notification settings - Fork 2
Add Clear button, add Domain header, housekeeping #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AndruC
wants to merge
3
commits into
HalilCan:master
Choose a base branch
from
AndruC:clear-plus-cleanup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,14 +33,13 @@ if (__debugMode) { | |
| //////////////////////////////////////// | ||
|
|
||
|
|
||
| function setRules(activeTab, hostname, cssText, callback) { | ||
| function setRules(activeTab, hostname, cssText) { | ||
| hostname = hostname.toString(); | ||
|
|
||
|
|
||
| let cssObject = cssTextToRules(cssText); | ||
| if (__debugMode) { | ||
| console.log(`cssObject in setRules:`); | ||
| console.log(cssObject); | ||
| console.log(cssObject); | ||
| } | ||
|
|
||
| let tempStorageObject; | ||
|
|
@@ -124,11 +123,9 @@ function printDate() { | |
| /// TEXTBOX INTERACTION /// | ||
|
|
||
|
|
||
| let setText = (newText) => { | ||
| let setText = (newText = "") => { | ||
| if (__debugMode) { | ||
| console.log(`---setText---`); | ||
| console.log(newText); | ||
| console.log(`--------`); | ||
| console.log(`---setText: ${newText} ---`); | ||
| } | ||
|
|
||
| textBox.value = newText; | ||
|
|
@@ -138,7 +135,7 @@ let getText = () => { | |
| return textBox.value; | ||
| } | ||
|
|
||
| setText("Oops. You should not be seeing this. Try reopening the window."); | ||
| setText("Initializing..."); | ||
|
|
||
| ////////////////////////// | ||
|
|
||
|
|
@@ -320,14 +317,10 @@ let insertCss = (cssString) => { | |
| console.log(`insertCss(`); | ||
| console.log(cssString); | ||
| } | ||
| // browser.tabs.insertCSS({code: cssString}).then(() => { | ||
| // insertedCss = cssString; | ||
| // }); | ||
|
|
||
| browser.tabs.sendMessage(activeTab.id, { | ||
| command: "insertCss", | ||
| cssString: cssString | ||
| // ok NOW i get why variable name keys might need to be explicit | ||
| }); | ||
| insertedCs = cssString; | ||
| } | ||
|
|
@@ -347,31 +340,6 @@ let removeCss = (cssString) => { | |
| ////// ASYNC FUNCTION SERIES BEGIN /////// | ||
|
|
||
| let listenForClicks = () => { | ||
| if (__debugMode) { | ||
| console.log(`listenForClicks BEGIN`); | ||
| console.log(ruleObject); | ||
| } | ||
|
|
||
| cssText = ruleContentToCssString(ruleObject['content']); | ||
|
|
||
| if (__debugMode) { | ||
| console.log(`listenForClicks > cssText`); | ||
| console.log(cssText); | ||
| } | ||
|
|
||
| if (cssText == "") { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to |
||
| if (__debugMode) { | ||
| console.log(`custom rules for ${hostname} not found`); | ||
| console.log(ruleObject); | ||
| setText(`${hostname}: There are no custom rules for this page.`); | ||
| // setText(JSON.stringify(ruleObject)); | ||
| } else { | ||
| setText(`${hostname}: There are no custom rules for this page.`); | ||
| } | ||
| } else { | ||
| setText(cssText); | ||
| } | ||
|
|
||
| document.addEventListener("click", (e) => { | ||
| if (__debugMode) { | ||
| console.log(e); | ||
|
|
@@ -380,17 +348,25 @@ let listenForClicks = () => { | |
|
|
||
| let targetId = e.target.id; | ||
|
|
||
| if (targetId == "apply-button") { | ||
| applyRules(); | ||
| } else if (targetId == "reset-button") { | ||
| // TODO: timer-based color fade reset button for "undo functionality" | ||
| setText(cssText); | ||
| switch (e.target.id) { | ||
| case "apply-button": | ||
| applyRules(); | ||
| break; | ||
| case "reset-button": | ||
| // TODO: timer-based color fade reset button for "undo functionality" | ||
| setText(cssText); | ||
| break; | ||
| case "clear-button": | ||
| setText(); | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| }) | ||
| }; | ||
|
|
||
| function applyRules() { | ||
| browser.tabs.query({currentWindow: true, active: true}).then((tabs) => { | ||
| browser.tabs.query({currentWindow: true, active: true}).then((tabs) => { | ||
| activeTab = tabs[0]; // Safe to assume there will only be one result | ||
|
|
||
| if (__debugMode) { | ||
|
|
@@ -413,11 +389,7 @@ browser.tabs.query({currentWindow: true, active: true}).then((tabs) => { | |
| let newText = getText(); | ||
|
|
||
| insertCss(newText); | ||
| setRules(activeTab, hostname, newText, (res) => { | ||
| if (__debugMode) { | ||
| console.log(`applyRules > setRules > saveRulesAsync callback ended:`); | ||
| } | ||
| }); | ||
| setRules(activeTab, hostname, newText); | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -445,6 +417,8 @@ function getTabUrl() { | |
| console.log(`hostname: ${hostname}`); | ||
| } | ||
|
|
||
| hostnameContainer.textContent = hostname; | ||
|
|
||
| let getHostnamePromise = browser.storage.sync.get(hostname); | ||
|
|
||
| getHostnamePromise.then((res) => { | ||
|
|
@@ -457,17 +431,25 @@ function getTabUrl() { | |
| hostnameFound = 1; | ||
| } | ||
|
|
||
| if(!res[hostname]) { | ||
| if (__debugMode) { | ||
| console.log(`${hostname} not found in browser.storage.local rules`); | ||
| } | ||
| } else { | ||
| let rules = res[hostname]; | ||
|
|
||
| if(!rules) { | ||
| if (__debugMode) { | ||
| console.log(`${hostname} WAS found in browser.storage.local rules`); | ||
| console.log(hostname); | ||
| console.log(JSON.parse(res[hostname])); | ||
| console.log(`couldn't find stored domain data`); | ||
| } | ||
| ruleObject = JSON.parse(res[hostname]); | ||
| } else { | ||
| console.log(`${hostname} WAS found in browser.storage.local rules`); | ||
| console.log(hostname); | ||
| console.log(JSON.parse(res[hostname])); | ||
| ruleObject = JSON.parse(rules); | ||
| } | ||
|
|
||
| cssText = ruleContentToCssString(ruleObject['content']); | ||
|
|
||
| if (cssText == "") { | ||
| setText(""); | ||
| } else { | ||
| setText(cssText); | ||
| } | ||
|
|
||
| listenForClicks(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,24 +3,26 @@ | |
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Custom Style Manager</title> | ||
| <link rel="stylesheet" href="css/popup-stylesheet.css" type="text/css"> | ||
| <link rel="stylesheet" href="css/popup-stylesheet.css" type="text/css"> | ||
| </head> | ||
|
|
||
| <body> | ||
|
|
||
| <p id = "hostname-container" class = "flex block-container"> </p> | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved into |
||
| <div id = "popup-viewport" class = "viewport flex-container flex-vertical-container"> | ||
| <div id = "textbox-container" class = "flex block-container"> | ||
| <textarea id = "popup-textarea" class = "block-container" spellcheck = "false"></textarea> | ||
| </div> | ||
| <div id = "controls-container" class = "flex flex-container flex-horizontal-container"> | ||
| <button id = "reset-button" class = "popup-button flex"> Reset </button> | ||
| <button id = "apply-button" class = "downward-box-shadow popup-button flex"> Apply </button> | ||
| </div> | ||
| </div> | ||
|
|
||
| <script src = "../rules.json"></script> | ||
| <script src = "js/popup.js"></script> | ||
| <div id = "popup-viewport" class = "viewport flex-container flex-vertical-container"> | ||
| <p id = "hostname-container" class = "flex block-container"> </p> | ||
| <div id = "textbox-container" class = "flex block-container"> | ||
| <textarea id = "popup-textarea" class = "block-container" spellcheck = "false"></textarea> | ||
| </div> | ||
| <div id = "controls-container" class = "gap flex flex-container flex-horizontal-container"> | ||
| <button id = "clear-button" class = "popup-button flex"> Clear </button> | ||
| <button id = "reset-button" class = "popup-button flex"> Undo </button> | ||
| <button id = "apply-button" class = "downward-box-shadow popup-button flex"> Apply </button> | ||
| </div> | ||
| </div> | ||
|
|
||
| <script src = "../rules.json"></script> | ||
| <script src = "js/popup.js"></script> | ||
|
|
||
| </body> | ||
| </html> | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to
:447