Started breaking extension in multiple smaller files.

This commit is contained in:
Tamius Han 2017-04-27 20:03:36 +02:00
parent 09ef70e96f
commit 62d40e25f5
11 changed files with 2450 additions and 838 deletions

View File

@ -64,7 +64,13 @@ For best results with autodetection, please make sure the following requirements
## Installing
### Temporary install
### Permanent install / stable
[v1.2.1 — Regular version — download from AMO](https://addons.mozilla.org/en/firefox/addon/ultrawidify/)
[v1.2.1 — Regular version — download from Chrome store](https://chrome.google.com/webstore/detail/ultrawidify/dndehlekllfkaijdlokmmicgnlanfjbi)
### Installing the current, github version
1. Clone this repo
2. Open up Firefox
@ -72,14 +78,7 @@ For best results with autodetection, please make sure the following requirements
4. Add temporary addon
5. Browse to wherever you saved it and select manifest.json
### Permanent install
[v1.2.1 — Regular version — download from AMO](https://addons.mozilla.org/en/firefox/addon/ultrawidify/)
[v1.2.1 — Regular version — download from Chrome store](https://chrome.google.com/webstore/detail/ultrawidify/dndehlekllfkaijdlokmmicgnlanfjbi)
## Known issues
## Known issues (in stable versions)
'More settings' button actually doesn't work at the moment.
@ -98,6 +97,12 @@ For best results with autodetection, please make sure the following requirements
## Changelog
###v1.3a1 (git/current version)
* Adding ability to add custom sites (in progress)
* Most of the extension is being completely rewritten to accomodate that feature, which means there's a serious regression with Netflix support (no netflix at the moment)
* I'm also trying to break the 1500 line behemoth into smaller files.
###v1.2.1 (AMO + Chrome)
* Fixed the bugs which caused aspect ratio to not be calculated properly.

84
buildext.sh Executable file
View File

@ -0,0 +1,84 @@
#!/bin/bash
# Takes all the files from 'src' and compiles it intro a single content script.
# Also compiles background scripts and settings pages.
#
# I'm using this over something like requirejs so my extension doesn't need even more
# dependencies.
#
# How does this work?
# 0. You're supposed to run this in the root directory of the extension.
# 1. see if file has any #include [filename] comments. If so, merge [filename] file
# into the current file (after checking if that file has any #include comments
# Compiled files are saved to /tmp.
#
# 2. After compiling file and its dependencies, check for presence of #location [directory]
# comments. [directory] is relative to the root directory of the extension
# 2.1 also check for #out, which defines filename.
#
# 3. Use '-nodebug' to remove all calls of console.log (to be implemented)
function flattenFileName {
echo $1 | sed 's/\//_/g'
}
fileList="";
function compileFile {
local file=$1
local flatfile=$(flattenFileName $file);
if [ -f /tmp/$flatfile ] ; then
return 0
fi;
fileList="$fileList $flatfile"
# let's take all the #included files and put them at the top
for f in $(grep "#include" $file | awk '{print $NF}') ; do
local lf=$f
fflat=$(flattenFileName $lf);
compileFile $lf
printf "\n//BEGIN included from $lf\n" >> /tmp/$flatfile
grep -Ev "#include|#location|#out" /tmp/$fflat >> /tmp/$flatfile
printf "//END included from $lf\n\n" >> /tmp/$flatfile
done
grep -Ev "#include|#location|#out" $file >> /tmp/$flatfile
}
cd src;
for file in *.js ; do
echo "main loop, we're looking at this file: $file"
compileFile $file
echo "Files compiled. Moving to location (if specified)"
outFile=$file
if grep -q "#out" $file ; then
outFile=$( grep "#out" $file | awk '{print $NF}')
fi
if grep -q "#location" $file ; then
location=$( grep "#location" $file | awk '{print $NF}')
echo "File will be saved to $location as $outFile"
cd ..
echo "// Autogenerated using buildext. This file should not be modified — modify source files instead." > $location/$outFile
grep -Ev "#location|#include|#out" /tmp/$(flattenFileName $file) >> $location/$outFile
cd src
fi
done
# perform cleanup
for file in $fileList ; do
rm /tmp/$file
done

974
js/uw.js

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Ultrawidify",
"version": "1.2.1.1",
"name": "Ultrawidify-git",
"version": "1.3a1",
"icons": {
"32":"res/icons/uw-32.png",

57
src/conf/keybinds.js Normal file
View File

@ -0,0 +1,57 @@
// Yeah hi /r/badcode.
// Anyway, because nazi localstorage flat out refuses to store arrays:
var DEFAULT_KEYBINDINGS = {
0:{ action: "fitw",
key: 'w',
modifiers: []
},
1:{
action: "fith",
key: 'e',
modifiers: []
},
2: {
action: "reset",
key: 'r',
modifiers: []
},
3: {
action: "zoom",
key: "z",
modifiers: []
},
4: {
action: "unzoom",
key: "u",
modifiers: []
},
5: {
action: "char",
targetAR: (21/9),
key: "d",
modifiers: []
},
6: {
action: "char",
targetAR: (16/9),
key: "s",
modifiers: []
},
7: {
action: "char",
targetAR: (16/10),
key: "x",
modifiers: []
},
8: {
action: "char",
targetAR: (4/3),
key: "c",
modifiers: []
},
9: {
action: "autoar",
key: "a",
modifiers: []
}
};

73
src/conf/sitesconf.js Normal file
View File

@ -0,0 +1,73 @@
var UW_SITES = {
youtube: {
enabled: true,
type: "official",
urlRules: ["youtu"],
player: {
name: "movie_player",
isClass: false,
},
iframe: {
name: "player",
isClass: false
},
sampleButton: {
class: "ytp-button ytp-settings-button",
index: 0,
buttonSizeBase: "x",
},
uiParent: {
name: "ytp-right-controls",
isClass: true,
insertStrat: "prepend",
},
autoar_imdb:{
enabled: false
}
},
netflix: {
enabled: true,
type: "official",
urlRules: ["netflix"],
player: {
name: "placeholder",
isClass: true,
},
sampleButton: {
class: "ytp-button ytp-settings-button",
index: 0,
buttonSizeBase: "x",
},
uiParent: {
name: "player-controls-wrapper",
isClass: true,
insertStrat: "append"
},
autoar_imdb:{
enabled: true,
title: "player-status-main-title",
isClass: true
}
},
dummy: {
type: "add new site",
urlRules: [""],
player: {
name: "",
isClass: false,
},
sampleButton: {
class: "ytp-button ytp-settings-button",
index: 0,
buttonSizeBase: "x",
},
uiParent: {
name: "",
isClass: false,
insertStrat: "prepend",
},
autoar_imdb:{
enabled: false
}
}
}

116
src/conf/uiconf.js Normal file
View File

@ -0,0 +1,116 @@
var UW_UI_BUTTONS = {
fitw: {
native_bar: true,
has_submenu: false,
button: true,
icon: "/res/img/ytplayer-icons/fitw.png",
text: "Fit to width",
onclick: function(){ changeCSS("fit", "fitw") }
},
fith: {
native_bar: true,
has_submenu: false,
button: true,
icon: "/res/img/ytplayer-icons/fith.png",
text: "Fit to height",
onclick: function(){ changeCSS("fit", "fith") }
},
reset: {
native_bar: true,
has_submenu: false,
button: true,
icon: "/res/img/ytplayer-icons/reset.png",
text: "Reset",
onclick: function(){ changeCSS("reset", "reset") }
},
zoom: {
native_bar: true,
has_submenu: false,
button: true,
icon: "/res/img/ytplayer-icons/zoom.png",
text: "Zoom",
onclick: function(){ changeCSS("fit", "zoom") }
},
unzoom: {
native_bar: true,
has_submenu: false,
button: true,
icon: "/res/img/ytplayer-icons/unzoom.png",
text: "Unzoom",
onclick: function(){ changeCSS("fit", "unzoom") }
},
zoom: {
native_bar: true,
has_submenu: false,
button: true,
icon: "/res/img/ytplayer-icons/zoom.png",
text: "Reset",
onclick: function(){ changeCSS("fit", "zoom") }
},
autoar: {
native_bar: false,
has_submenu: false,
button: false,
text: "Detect aspect ratio via 3rd party",
onclick: function(){ manual_autoar()}
},
settings: {
native_bar: true,
button: true,
icon: "/res/img/ytplayer-icons/settings.png",
text: "Settings",
has_submenu: true,
submenu: [ "fitw","fith","reset","zoom","unzoom","autoar","ar" ],
top_level: true,
submenu_id: "uw_settings_menu",
onclick: function(){ toggleMenu("uw_settings_menu") }
},
ar: {
native_bar: false,
button: false,
text: "Force aspect ratio",
has_submenu: true,
submenu: [ "ar219", "ar169", "ar1610", "ar43" ],
submenu_id: "uw_force_ar_menu",
onclick: function(){ showMenu("uw_force_ar_menu") }
},
ar219: {
native_bar: false,
button: false,
text: "21:9",
has_submenu: false,
onclick: function(){ changeCSS("char", ( 21/9 )); }
},
ar169: {
native_bar: false,
button: false,
text: "16:9",
has_submenu: false,
onclick: function(){ changeCSS("char", ( 16/9 )); }
},
ar1610: {
native_bar: false,
button: false,
text: "16:10",
has_submenu: false,
onclick: function(){ changeCSS("char", ( 1.6 )); }
},
ar43: {
native_bar: false,
button: false,
text: "4:3",
has_submenu: false,
onclick: function(){ changeCSS("char", ( 4/3 )); }
}
}
var UW_UI_BANLIST = {
youtube: {
autoar: "all"
},
netflix: {
settings: "all"
}
}

View File

@ -0,0 +1,11 @@
usebrowser = "firefox";
if(typeof browser === "undefined"){ // This means we're probably not on Firefox.
if(chrome){
browser = chrome;
usebrowser = "chrome";
}
}
else{
usebrowser = "firefox";
}

12
src/lib/libopts.js Normal file
View File

@ -0,0 +1,12 @@
// setopt in getopt. Shranita oz. dobita stvari iz skladišča
// setopt, getopt. They set/get stuff from the storage
function setopt(item){
browser.storage.local.set(item);
}
function getopt(prop, callback){
if(usebrowser == "chrome")
browser.storage.local.get(prop, callback);
else
browser.storage.local.get(prop).then(callback);
}

12
src/lib/optinit.js Normal file
View File

@ -0,0 +1,12 @@
IGNORE_STORAGE_CHANGES = true;
// getopt( "ultrawidify_uiban", function (opt) {
// if(! opt || opt.ultrawidify_uiban === undefined){
// if(debugmsg)
// console.log("uw::extsetup_uiban | ui ban missing from storage. Setting defaults.");
// browser.storage.local.set({ultrawidify_uiban: UW_UI_BANLIST});
// }
// }
IGNORE_STORAGE_CHANGES = false;

1692
src/uw.js Normal file

File diff suppressed because it is too large Load Diff