Skip to content

Commit 81a5d58

Browse files
authored
Merge pull request #14 from MonoScyron/dev
Dev into main
2 parents bc2147a + 6b2a573 commit 81a5d58

File tree

15 files changed

+526
-431
lines changed

15 files changed

+526
-431
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 52 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Firefox extension for the fanfiction website [ArchiveOfOurOwn](http://archiveofo
1010

1111
This guide details how to install any add-on in general on Firefox Nightly browsers on mobile.
1212

13-
Note: This extension should work on mobile, but it has not been extensively tested there. Please report any bugs you find in the issues tab!
13+
Note: This extension should work on mobile, but it has not been extensively tested there. Please report any bugs you
14+
find in the issues tab!
1415

1516
1. Create a collection on the [Firefox Add-ons collections page](https://addons.mozilla.org/en-US/firefox/collections/)
1617
2. Add "AO3 Enhancer" (Or any other add-on) to that collection
@@ -27,6 +28,7 @@ Most features are disabled by default. Please click on the extension icon to ena
2728
### Enhancer Additions
2829

2930
- **Kudos to Hit Ratio**: Adds a kudos to hit percentage to the stats list of a work.
31+
- **Hide Fics by Ratio**: Automatically hides works with too low kudos to hit ratio.
3032
- **Hide Fics With Too Many Fandoms**: Automatically hides works with too many fandoms.
3133

3234
### Built-in Filtering Settings
@@ -47,7 +49,6 @@ These are features I currently plan on adding. Please suggest additional feature
4749
- [ ] Filter & sort your marked-for-later fics
4850
- [ ] Filter fics by if already read
4951
- [ ] Filter fics by individual fic ID
50-
- [ ] Filter fics by ratio of kudos to hits
5152
- [ ] Add ability to get notified when fics are completed
5253

5354
#### TODO Lower Priority
@@ -80,6 +81,7 @@ This will cause webpack to optimize for production. To build for production, run
8081
`npm run build:prod`
8182

8283
#### Add-on Compilation
84+
8385
Latest version of the add-on was built using these software versions:
8486

8587
```
@@ -93,11 +95,10 @@ Node: v18.12.1
9395

9496
This addon was inspired by the extensions I use to browse AO3:
9597

96-
- [AO3 Enhancements](https://github.com/jsmnbom/ao3-enhancements) by `jsmnbom`
97-
- [AO3 Tag Blocker](https://github.com/ao3-tag-blocker/tag-blocker)
98-
99-
The icon is a modified version of the icon for [AO3 Enhancements](https://github.com/jsmnbom/ao3-enhancements) by `jsmnbom`.
98+
- [AO3 Enhancements](https://github.com/jsmnbom/ao3-enhancements) by `jsmnbom`
99+
- [AO3 Tag Blocker](https://github.com/ao3-tag-blocker/tag-blocker)
100100

101-
The options page background is CC-BY-4.0 by [Hero Patterns](http://www.heropatterns.com/).
101+
The icon is a modified version of the icon for [AO3 Enhancements](https://github.com/jsmnbom/ao3-enhancements)
102+
by `jsmnbom`.
102103

103-
The eye and arrow icons used are MIT license by [Heroicons](https://heroicons.com/).
104+
The options page background is CC-BY-4.0 by [Hero Patterns](http://www.heropatterns.com/).

manifest.json

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
{
2-
"manifest_version": 2,
3-
"name": "AO3 Enhancer",
4-
"version": "0.0.5",
5-
"description": "Enhancement extension for Archive of Our Own.",
6-
"author": "MonoScyron",
7-
"icons": {
8-
"48": "/build/icons/logo-48.png",
9-
"96": "/build/icons/logo-96.png"
10-
},
11-
"permissions": [
12-
"storage",
13-
"webRequest",
14-
"webRequestBlocking",
2+
"manifest_version": 2,
3+
"name": "AO3 Enhancer",
4+
"version": "0.0.6",
5+
"description": "Enhancement extension for Archive of Our Own.",
6+
"author": "MonoScyron",
7+
"icons": {
8+
"48": "/build/icons/logo-48.png",
9+
"96": "/build/icons/logo-96.png"
10+
},
11+
"permissions": [
12+
"storage",
13+
"webRequest",
14+
"webRequestBlocking",
15+
"https://archiveofourown.org/*"
16+
],
17+
"browser_action": {
18+
"default_icon": "/build/icons/logo-32.png",
19+
"default_title": "AO3 Enhancer"
20+
},
21+
"options_ui": {
22+
"page": "build/options/options.html",
23+
"open_in_tab": true
24+
},
25+
"background": {
26+
"scripts": [
27+
"build/background/bg_bundle.js"
28+
]
29+
},
30+
"content_scripts": [
31+
{
32+
"matches": [
1533
"https://archiveofourown.org/*"
16-
],
17-
"browser_action": {
18-
"default_icon": "/build/icons/logo-32.png",
19-
"default_title": "AO3 Enhancer"
20-
},
21-
"options_ui": {
22-
"page": "build/options/options.html",
23-
"open_in_tab": true
24-
},
25-
"background": {
26-
"scripts": [
27-
"build/background/bg_bundle.js"
28-
]
29-
},
30-
"content_scripts": [
31-
{
32-
"matches": [
33-
"https://archiveofourown.org/*"
34-
],
35-
"js": [
36-
"build/content_scripts/cs_bundle.js"
37-
],
38-
"css": [
39-
"build/css/enhancer.css"
40-
]
41-
}
42-
],
43-
"browser_specific_settings": {
44-
"gecko": {
45-
"id": "ao3-enhancer@MonoScyron",
46-
"strict_min_version": "57.0"
47-
}
34+
],
35+
"js": [
36+
"build/content_scripts/cs_bundle.js"
37+
],
38+
"css": [
39+
"build/css/enhancer.css"
40+
]
4841
}
42+
],
43+
"browser_specific_settings": {
44+
"gecko": {
45+
"id": "ao3-enhancer@MonoScyron",
46+
"strict_min_version": "57.0"
47+
}
48+
}
4949
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"scripts": {
3+
"prod": "npm run build:prod && npm run zip",
4+
"dev": "npm run build:dev && npm run zip",
35
"build-cs:dev": "webpack --mode=development --config cs-webpack.config.js",
46
"build-bg:dev": "webpack --mode=development --config bg-webpack.config.js",
57
"build-op:dev": "webpack --mode=development --config op-webpack.config.js",
@@ -8,9 +10,7 @@
810
"build-op:prod": "webpack --mode=production --config op-webpack.config.js",
911
"build:dev": "npm run build-cs:dev && npm run build-bg:dev && npm run build-op:dev",
1012
"build:prod": "npm run build-cs:prod && npm run build-bg:prod && npm run build-op:prod",
11-
"zip": "@powershell IF(!(Test-Path dist)) { mkdir dist }; tar.exe -a -c -f ./dist/ao3-enhancer-firefox.zip build manifest.json",
12-
"dev": "npm run build:dev && npm run zip",
13-
"prod": "npm run build:prod && npm run zip"
13+
"zip": "@powershell IF(!(Test-Path dist)) { mkdir dist }; tar.exe -a -c -f ./dist/ao3-enhancer-firefox.zip build manifest.json"
1414
},
1515
"dependencies": {
1616
"@types/firefox-webext-browser": "^109.0.0",

src/content_scripts/hide-works.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { WorkElement } from "../export/objects";
44
* Checks each work on page and hides them if necessary
55
* @param works Works on page
66
* @param document Document the works belong to
7+
* @param settings Settings of extension
78
*/
89
export function hideWorks(works: WorkElement[], document: Document, settings: { [key: string]: any }) {
910
let parser = new DOMParser();
1011
works.forEach(w => {
11-
var reason = shouldHide(w, settings);
12+
let reason = shouldHide(w, settings);
1213
if(reason != null)
1314
hideWork(w, reason, document, parser);
1415
});
@@ -23,10 +24,18 @@ export function hideWorks(works: WorkElement[], document: Document, settings: {
2324
*/
2425
function shouldHide(work: WorkElement, settings: { [key: string]: any }): string | null {
2526
// ! When returning string, should be in form of `([Reason why work is hidden]: ${Value of reason})`
27+
28+
// Hide by num fandoms
2629
if(!Number.isNaN(settings.hideByNumFandom) && work.fandoms.length > settings.hideByNumFandom) {
2730
return `(Too many fandoms: ${work.fandoms.length})`
2831
}
29-
32+
// Hide by ratio
33+
else if(work.hits == 0) {
34+
return `(Ratio too small: 0 hits)`
35+
}
36+
else if(work.kudos == 0 || work.kudos / work.hits < settings.hideByRatio / 100.0) {
37+
return `(Ratio too small: ${Math.round((work.kudos / work.hits) * 1000) / 10}%)`
38+
}
3039
return null;
3140
}
3241

src/content_scripts/onload.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ browser.storage.local.get(STORAGE_KEYS).then((value) => {
1818
/**
1919
* Executed after all promises are fulfilled
2020
* @param value Local storage values of all saved settings
21+
* @param document Document of the current page
2122
*/
2223
function onloadPromise(value: { [key: string]: any }, document: Document): void {
23-
var works = constructWorkList(document);
24+
let works = constructWorkList(document);
2425

2526
// Add kudos to hit ratio if enabled
2627
if(value.kudosHitRatio)
@@ -29,6 +30,4 @@ function onloadPromise(value: { [key: string]: any }, document: Document): void
2930
// Hide works if page not a work page
3031
if(document.URL.split('/')[3] != "works")
3132
hideWorks(works, document, value);
32-
}
33-
34-
// TODO: On load to user marked-for-later page, filter it (https://www.npmjs.com/package/ao3api for how to POST requests)
33+
}

src/content_scripts/ratio.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { WorkElement } from '../export/objects';
22

33
/**
4-
* Adds kudos to hit ratios to works on the page
5-
* @param document Document of the page
4+
* Adds kudos to hit ratios to works on the page
5+
* @param workList List of works on page
66
*/
77
export function addKudosToHitRatios(workList: WorkElement[]): void {
88
// Create ratio elements for all works on page
@@ -11,11 +11,11 @@ export function addKudosToHitRatios(workList: WorkElement[]): void {
1111

1212
workList.forEach((work, i) => {
1313
if(work.kudos != 0 && work.hits != 0) {
14-
var ratio_dt = document.createElement("dt");
14+
let ratio_dt = document.createElement("dt");
1515
ratio_dt.className = `kudos-to-hit-ratio`;
1616
ratio_dt.innerText = "Ratio:";
1717

18-
var ratio_dd = document.createElement("dd");
18+
let ratio_dd = document.createElement("dd");
1919
ratio_dd.className = `ratio`;
2020
ratio_dd.innerText = Math.round((work.kudos / work.hits) * 1000) / 10 + "%";
2121

@@ -29,7 +29,7 @@ export function addKudosToHitRatios(workList: WorkElement[]): void {
2929
});
3030

3131
// Add list of ratio elements to works
32-
for(var i = 0; i < workList.length; i++) {
32+
for(let i = 0; i < workList.length; i++) {
3333
if(ratio_dtList[i] != null && ratio_ddList[i] != null) {
3434
workList[i].element?.querySelector('dl.stats')?.append(ratio_dtList[i]!, ratio_ddList[i]!);
3535
}

src/content_scripts/works.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function constructWorkList(document: Document): WorkElement[] {
1313
}
1414
else {
1515
let rawWorks = constructRawWorkList(document);
16-
for(var i = 0; i < rawWorks.length; i++) {
16+
for(let i = 0; i < rawWorks.length; i++) {
1717
workList.push(constuctWorkElement(rawWorks[i]));
1818
}
1919
}

0 commit comments

Comments
 (0)