Skip to content
Permalink
Browse files

Version 3.1

Re-added the ability to make additions to the 'Apply RetroTxt to text files hosted on these websites'
  • Loading branch information...
bengarrett committed Nov 30, 2018
1 parent 2ec70f9 commit 7e58604a9a738760175fce56fdd9395ac767eb26
@@ -7,4 +7,7 @@ web-ext-artifacts

# Visual Studio Code
.vscode/tasks.json
node_modules
node_modules

# Other
notes.md
@@ -83,7 +83,7 @@ While RetroTxt uses a [GNU Lesser General Public License v3.0](https://chooseali

## Credits

RetroTxt by [Ben Garrett](https://bens.zone/) on [Twitter @bens_zone](https://twitter.com/bens_zone) and [GitHub](https://github.com/bengarrett/)
RetroTxt by [Ben Garrett](https://devtidbits.com/ben-garrett/) on [Twitter @bens_zone](https://twitter.com/bens_zone) and [GitHub](https://github.com/bengarrett/)

RetroTxt ANSI logo Zeus II [Twitter @Zeus_II](https://twitter.com/Zeus_II)

@@ -220,6 +220,12 @@ main > section .section-content ul li {
padding-bottom: 2px;
padding-top: 2px;
}
main > section #please-apply {
color: darkorange;
display: none;
text-align: right;
margin-right: 2em;
}

footer > .box {
display: flex;
@@ -314,6 +314,10 @@ main > section .config-row-basis {
main > section .config-row.separator-block {
padding-bottom: 6px;
}
main > section #please-apply {
color: darkorange;
display: none;
}
/* About tab selection */
main > section .about-title {
flex-basis: 7em;
@@ -334,3 +338,6 @@ footer > .box {
margin-top: 12px;
width: 30em;
}
footer > .box > #unittest {
display: none;
}
@@ -1,5 +1,14 @@
# RetroTxt Changes

## 3.1

### December 2018

- Re-added the ability to make additions to the _Apply RetroTxt to text files hosted on these websites_ list that was disabled in v3.0.
- Fixed the Zeus II logo for the welcome screen breaking on Linux.
- Fixed _Homepage URL_ in the Firefox addon tab.
- Fixed incorrect links in `README.md`.

## 3.0

### Highlights
@@ -413,9 +413,10 @@
<input type="checkbox" id="run-web-urls"></label>
</div>
</div>
<div id="please-apply">Please click this checkbox to apply your new setting <strong>⤴</strong></div>
<div class="config-row">
<label>
<textarea id="run-web-urls-permitted" rows="3" disabled></textarea>
<textarea id="run-web-urls-permitted" rows="4"></textarea>
</label>
</div>
<!-- apply to downloads -->
@@ -419,6 +419,7 @@
<!-- Config tab -->
<section class="tabcontent" id="tab3">
<!-- apply to websites -->
<div id="please-apply">Please click this checkbox to apply your new setting</div>
<div class="config block">
<div class="config-content">
<i class="material-icons">web</i>

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -43,6 +43,7 @@
"downloads.open",
"tabs",
"file:///*/",
"*://*/*",
"*://*.16colo.rs/*",
"*://*.defacto2.net/*",
"*://*.gutenberg.org/*",
@@ -62,8 +63,8 @@
"*://*.retrotxt.com/*"
],
"short_name": "RetroTxt",
"version": "3.0.3",
"version_name": "3.0",
"version": "3.1.0",
"version_name": "3.1",
"web_accessible_resources": [
"css/*.css",
"fonts/woff2/*.woff2",
@@ -43,6 +43,7 @@
"downloads.open",
"tabs",
"file:///*/",
"*://*/*",
"*://*.16colo.rs/*",
"*://*.defacto2.net/*",
"*://*.gutenberg.org/*",
@@ -62,8 +63,8 @@
"*://*.retrotxt.com/*"
],
"short_name": "RetroTxt",
"version": "3.0.3",
"version_name": "3.0",
"version": "3.1.0",
"version_name": "3.1",
"web_accessible_resources": [
"css/*.css",
"fonts/woff2/*.woff2",
@@ -37,8 +37,7 @@
"default_locale": "en_US",
"description": "Turn pieces of ANSI based text art and ASCII, NFO plain text into HTML.",
"developer": {
"name": "Ben Garrett",
"url": "https://github.com/bengarrett"
"name": "Ben Garrett"
},
"homepage_url": "https://retrotxt.com",
"icons": {
@@ -51,6 +50,7 @@
"optional_permissions": [
"tabs",
"file:///*/",
"*://*/*",
"*://*.16colo.rs/*",
"*://*.defacto2.net/*",
"*://*.gutenberg.org/*",
@@ -72,7 +72,7 @@
"*://*.retrotxt.com/*"
],
"short_name": "RetroTxt",
"version": "3.0.3",
"version": "3.1.0",
"web_accessible_resources": [
"css/*.css",
"fonts/woff2/*.woff2",
@@ -866,7 +866,12 @@ class Downloads {
async listen() {
if (FindEngine() === `gecko`) return
// exit when chrome.downloads is inaccessible due Extensions configurations
if (`downloads` in chrome === false) return
if (`downloads` in chrome === false)
return console.warn(`chrome.downloads API is inaccessible`)
if (`onCreated` in chrome.downloads === false)
return console.warn(
`chrome.downloads API onCreated event is inaccessible`
)
const downloads = new Downloads()
const security = new Security(`downloads`, `downloads`)
const test = security.test()
@@ -1192,7 +1197,6 @@ class WebExtension {
runAt: `document_start`
},
() => {
console.log(chrome.runtime)
if (persistent && typeof chrome.runtime.lastError !== `undefined`)
return lastError()
// automatic invocation that will be run after this eventpage.js page is loaded and at the start of the document
@@ -96,6 +96,7 @@ function localStore(key = ``, value = ``) {
/**
* Grants and removes WebExtension access permissions.
* see: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/permissions
* match patterns: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns
* @class Security
*/
class Security {
@@ -104,6 +105,8 @@ class Security {
* @param [type=``] checkbox type, either `downloads`, `files` or `http`
*/
constructor(type = ``) {
const config = new Configuration()
this.domains = config.domainsString()
// IMPORTANT! These Map values must sync to those in the Security class in eventpage.js
const permissions = new Map()
.set(`downloads`, [`downloads`, `downloads.open`, `tabs`])
@@ -122,6 +125,18 @@ class Security {
this.origins = origins.get(`${type}`)
this.elementId = elements.get(`${type}`)
this.type = type
// special case for user edited textarea
const askAllWeb =
this.domains !== localStorage.getItem(`runWebUrlsPermitted`) // Bool value
if (type === `http` && askAllWeb) {
if (!origins.get(`http`).includes(`*://*/*`))
origins.get(`http`).push(`*://*/*`)
}
// permissions needed for user supplied websites, edited in the textarea
this.allWebPermissions = {
origins: [`*://*/*`],
permissions: [`tabs`]
}
}
/**
* Creates a collection of origins from a predetermined list of domains.
@@ -131,7 +146,7 @@ class Security {
const domains = chrome.runtime.getManifest().optional_permissions
let origins = []
domains.filter(domain => {
if (domain.slice(0, 4) === `*://`) {
if (domain.slice(0, 6) === `*://*.`) {
origins = origins.concat(this.collection(domain))
}
})
@@ -147,7 +162,48 @@ class Security {
const hostname = noScheme.split(`/`, 1)[0]
return [`*://${hostname}/*`]
}

/**
* Textarea onChanged event that updates the `this.allWebPermissions` permission.
* @param [request=true] request `true` or remove `false` permission
*/
allWeb(request = false) {
if (this.type !== `http`) return
switch (request) {
case true:
// do nothing
break
case false:
chrome.permissions.contains(this.allWebPermissions, result => {
if (result === true) {
chrome.permissions.remove(this.allWebPermissions, result => {
if (result === false)
console.warn(
`Could not remove the permissions %s %s`,
this.allWebPermissions.origins,
this.allWebPermissions.permissions
)
this.permissionsCallback()
})
}
})
break
}
}
/**
* Display a notification "Please " when the textarea onChanged is triggered.
* @param [display=false] show `true` or remove `false` the notification
*/
allWebNotice(display = false) {
const checkbox = document.getElementById(`run-web-urls`)
const div = document.getElementById(`please-apply`)
if (display) {
checkbox.checked = false
div.style.display = `block`
} else {
div.style.display = `none`
}
this.permissionsCallback()
}
/**
* Initialise on-change event listeners for checkboxes and the <textarea>.
*/
@@ -165,13 +221,45 @@ class Security {
const checkbox = document.getElementById(`${this.elementId}`)
checkbox.addEventListener(`change`, () => {
const value = document.getElementById(`${this.elementId}`).checked
this.allWeb(false)
this.checkedEvent(value)
toggles()
})
// textarea event listeners
const textarea = document.getElementById(`run-web-urls-permitted`)
textarea.addEventListener(`change`, () => {
if (this.type !== `http`) return
const askAllWeb = this.domains === textarea.value
if (RetroTxt.developer) console.log(`Textarea has been updated`)
if (askAllWeb) {
// textarea has been reset
this.origins.pop()
this.allWeb(false)
this.allWebNotice(true)
} else {
// textarea has been modified
chrome.permissions.contains(this.allWebPermissions, result => {
if (result === false) {
// `*://*/*` permission has not been granted
if (!this.origins.includes(`*://*/*`)) {
// append `*://*/*` to the permissions origins and then ask the
// user to toggle the checkbox input to apply the new permissions.
// webextensions can only ask for new permissions using user toggles
this.origins.push(`*://*/*`)
this.allWebNotice(true)
} else {
// do nothing
}
} else {
// `*://*/*` permission has been granted
this.allWebNotice(false)
}
})
}
})
// checkbox toggles
const toggles = () => {
const files = document.getElementById(`run-file-urls`)
//const downloads = document.getElementById(`run-file-downloads`)
const value = document.getElementById(`${this.elementId}`).checked
let monitor = false // for run-file-downloads
// special cases that have permission dependencies
@@ -188,6 +276,11 @@ class Security {
files.disabled = false
}
break
case `run-web-urls`:
this.allWebNotice(false)
// if value is false, disable textarea
textarea.disabled = !value
break
}
}
}
@@ -197,10 +290,9 @@ class Security {
* @param testResult a collection of permissions
*/
checkedEvent(request = true, testResult = this.test()) {
console.trace(this.type, testResult)
switch (this.type) {
case `http`:
case `downloads`:
case `http`:
this.permissionSet(request, testResult)
break
case `files`:
@@ -215,7 +307,6 @@ class Security {
* @param testResult a collection of permissions
*/
permissionSet(request = true, testResult) {
console.log(`testResult`, request, testResult)
const items = testResult.permissions.concat(testResult.origins).join(`, `)
const workaround = { permissions: [`tabs`] }
switch (request) {
@@ -228,6 +319,7 @@ class Security {
})
break
default:
this.allWeb(false)
chrome.permissions.remove(testResult, result => {
if (RetroTxt.developer)
console.log(`%s: request to remove permissions [%s]`, result, items)
@@ -309,6 +401,19 @@ class Security {
this.elementId
)
checkbox.checked = granted
if (this.elementId === `run-web-urls`) {
this.textareaInitialise(granted)
}
}
/**
* Set the textarea checked state.
* @param [granted=false] `true` checked or `false` unchecked
*/
textareaInitialise(granted = false) {
if (this.type !== `http`) return
const textarea = document.getElementById(`run-web-urls-permitted`)
if (!(`disabled` in textarea)) return
textarea.disabled = !granted
}
/**
* Reveals the checkbox <div> block on the Options dialogue.

0 comments on commit 7e58604

Please sign in to comment.
You can’t perform that action at this time.