rewrite finished to the point where extension doesn't outright crash. Nothing works, though.
This commit is contained in:
parent
0ac051d5d5
commit
3686341677
@ -1,6 +1,6 @@
|
|||||||
// Set prod to true when releasing
|
// Set prod to true when releasing
|
||||||
_prod = true;
|
// _prod = true;
|
||||||
// _prod = false;
|
_prod = false;
|
||||||
|
|
||||||
Debug = {
|
Debug = {
|
||||||
debug: true,
|
debug: true,
|
||||||
|
@ -27,7 +27,7 @@ class EdgeDetect{
|
|||||||
}
|
}
|
||||||
|
|
||||||
findBars(image, sampleCols, direction = EdgeDetectPrimaryDirection.VERTICAL, quality = EdgeDetectQuality.IMPROVED, guardLineOut){
|
findBars(image, sampleCols, direction = EdgeDetectPrimaryDirection.VERTICAL, quality = EdgeDetectQuality.IMPROVED, guardLineOut){
|
||||||
var fastCandidates, edgeCandidates, bars,
|
var fastCandidates, edgeCandidates, bars;
|
||||||
if (direction == EdgeDetectPrimaryDirection.VERTICAL) {
|
if (direction == EdgeDetectPrimaryDirection.VERTICAL) {
|
||||||
fastCandidates = this.findCandidates(image, sampleCols, guardLine);
|
fastCandidates = this.findCandidates(image, sampleCols, guardLine);
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ class EdgeDetect{
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
edgePostprocess = function(edges){
|
edgePostprocess(edges){
|
||||||
var edgesTop = [];
|
var edgesTop = [];
|
||||||
var edgesBottom = [];
|
var edgesBottom = [];
|
||||||
var alignMargin = this.conf.context.height * ExtensionConf.arDetect.allowedMisaligned;
|
var alignMargin = this.conf.context.height * ExtensionConf.arDetect.allowedMisaligned;
|
||||||
|
@ -99,7 +99,7 @@ class PlayerData {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var isFullScreen = PlayerData.isFullScreen();
|
var isFullScreen = this.isFullScreen();
|
||||||
|
|
||||||
var trustCandidateAfterGrows = 2; // if candidate_width or candidate_height increases in either dimensions this many
|
var trustCandidateAfterGrows = 2; // if candidate_width or candidate_height increases in either dimensions this many
|
||||||
// times, we say we found our player. (This number ignores weird elements)
|
// times, we say we found our player. (This number ignores weird elements)
|
||||||
|
@ -3,7 +3,7 @@ class VideoData {
|
|||||||
constructor(video){
|
constructor(video){
|
||||||
this.video = video;
|
this.video = video;
|
||||||
// todo: add ArDetect instance
|
// todo: add ArDetect instance
|
||||||
this.arDetector = new ArDetector(video);
|
this.arDetector = new ArDetector(video); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting
|
||||||
this.resizer = new Resizer(this);
|
this.resizer = new Resizer(this);
|
||||||
this.player = new PlayerData(this);
|
this.player = new PlayerData(this);
|
||||||
|
|
||||||
@ -27,5 +27,12 @@ class VideoData {
|
|||||||
this.resizer.setLastAr(lastAr);
|
this.resizer.setLastAr(lastAr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setAr(ar, lastAr){
|
||||||
|
this.resizer.setAr(ar, lastAr);
|
||||||
|
}
|
||||||
|
|
||||||
|
setStretchMode(stretchMode){
|
||||||
|
this.resizer.setStretchMode(stretchMode);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -18,7 +18,7 @@ class ArDetector {
|
|||||||
this.guardLine = new GuardLine(this);
|
this.guardLine = new GuardLine(this);
|
||||||
this.edgeDetector = new EdgeDetect(this);
|
this.edgeDetector = new EdgeDetect(this);
|
||||||
this.debugCanvas = new DebugCanvas(this);
|
this.debugCanvas = new DebugCanvas(this);
|
||||||
setup(ExtensionConf.arDetect.hSamples, ExtensionConf.arDetect.vSamples);
|
this.setup(ExtensionConf.arDetect.hSamples, ExtensionConf.arDetect.vSamples);
|
||||||
}
|
}
|
||||||
|
|
||||||
setup(cwidth, cheight){
|
setup(cwidth, cheight){
|
||||||
@ -226,7 +226,7 @@ class ArDetector {
|
|||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
processAr = function(edges){
|
processAr(edges){
|
||||||
|
|
||||||
if(Debug.debug && Debug.debugArDetect){
|
if(Debug.debug && Debug.debugArDetect){
|
||||||
console.log("[ArDetect::_ard_processAr] processing ar. sample width:", this.canvas.width, "; sample height:", this.canvas.height, "; edge top:", edges.top);
|
console.log("[ArDetect::_ard_processAr] processing ar. sample width:", this.canvas.width, "; sample height:", this.canvas.height, "; edge top:", edges.top);
|
||||||
|
@ -3,7 +3,7 @@ class DebugCanvas {
|
|||||||
this.conf = ardConf;
|
this.conf = ardConf;
|
||||||
}
|
}
|
||||||
|
|
||||||
init = async function(canvasSize, canvasPosition){
|
init(canvasSize, canvasPosition) {
|
||||||
console.log("initiating DebugCanvas")
|
console.log("initiating DebugCanvas")
|
||||||
|
|
||||||
var body = document.getElementsByTagName('body')[0];
|
var body = document.getElementsByTagName('body')[0];
|
||||||
@ -34,12 +34,12 @@ class DebugCanvas {
|
|||||||
console.log("debug canvas is:", this.canvas, "context:", this.context)
|
console.log("debug canvas is:", this.canvas, "context:", this.context)
|
||||||
}
|
}
|
||||||
|
|
||||||
setBuffer = function(buffer) {
|
setBuffer(buffer) {
|
||||||
// this.imageBuffer = buffer.splice(0);
|
// this.imageBuffer = buffer.splice(0);
|
||||||
this.imageBuffer = new Uint8ClampedArray(buffer);
|
this.imageBuffer = new Uint8ClampedArray(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
trace = function(arrayIndex, colorClass){
|
trace(arrayIndex, colorClass) {
|
||||||
this.imageBuffer[arrayIndex ] = colorClass.colorRgb[0];
|
this.imageBuffer[arrayIndex ] = colorClass.colorRgb[0];
|
||||||
this.imageBuffer[arrayIndex+1] = colorClass.colorRgb[1];
|
this.imageBuffer[arrayIndex+1] = colorClass.colorRgb[1];
|
||||||
this.imageBuffer[arrayIndex+2] = colorClass.colorRgb[2];
|
this.imageBuffer[arrayIndex+2] = colorClass.colorRgb[2];
|
||||||
|
@ -6,19 +6,23 @@ class PageInfo {
|
|||||||
this.hasVideos = false;
|
this.hasVideos = false;
|
||||||
this.siteDisabled = false;
|
this.siteDisabled = false;
|
||||||
this.videos = [];
|
this.videos = [];
|
||||||
|
|
||||||
|
|
||||||
|
this.rescan();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rescan(count){
|
||||||
|
var vids = document.getElementsByTagName('video');
|
||||||
|
|
||||||
rescan(){
|
if(!vids || vids.length == 0){
|
||||||
var videos = document.getElementsByTagName('video');
|
|
||||||
|
|
||||||
if(!videos || videos.length == 0){
|
|
||||||
this.hasVideos = false;
|
this.hasVideos = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debugger;
|
||||||
|
|
||||||
// add new videos
|
// add new videos
|
||||||
for(video of videos){
|
for(var video of vids){
|
||||||
var existing = this.videos.find( (x) => {
|
var existing = this.videos.find( (x) => {
|
||||||
if (x == video.video)
|
if (x == video.video)
|
||||||
return x;
|
return x;
|
||||||
@ -30,20 +34,30 @@ class PageInfo {
|
|||||||
if(existing){
|
if(existing){
|
||||||
video.video = existing;
|
video.video = existing;
|
||||||
} else {
|
} else {
|
||||||
videos.push(
|
this.videos.push(
|
||||||
new VideoData(video)
|
new VideoData(video)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initAr(){
|
||||||
|
for(var vd in this.videos){
|
||||||
|
vd.initAr();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _pi_hasVideos = function(){
|
setAr(ar){
|
||||||
// return true;
|
// TODO: find a way to only change aspect ratio for one video
|
||||||
var videos = document.getElementsByTagName("video");
|
for(var vd in this.videos){
|
||||||
if(videos.length == 0)
|
vd.setAr(ar)
|
||||||
return false;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if(videos[0].style.display == "none") // in this case ultrawidify doesn't even work
|
setStretchMode(sm){
|
||||||
// return false;
|
for(var vd in this.videos){
|
||||||
|
vd.setStretchMode(ar)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
if(Debug.debug)
|
if(Debug.debug)
|
||||||
console.log("Loading: Resizer.js");
|
console.log("Loading: Resizer.js");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var StretchMode = {
|
var StretchMode = {
|
||||||
NO_STRETCH = 0,
|
NO_STRETCH: 0,
|
||||||
CONDITIONAL = 1,
|
CONDITIONAL: 1,
|
||||||
FULL = 2
|
FULL: 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
96
js/uw.js
96
js/uw.js
@ -12,51 +12,23 @@ if(Debug.debug){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class VideoManager {
|
|
||||||
|
|
||||||
|
|
||||||
refresh(){
|
async function init(){
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// load all settings from localStorage:
|
|
||||||
|
|
||||||
async function main(){
|
|
||||||
if(Debug.debug)
|
if(Debug.debug)
|
||||||
console.log("[uw::main] loading configuration ...");
|
console.log("[uw::main] loading configuration ...");
|
||||||
|
|
||||||
// load settings
|
// load settings
|
||||||
var isSlave = true;
|
var isSlave = true;
|
||||||
await Settings.init(isSlave);
|
await Settings.init(isSlave);
|
||||||
var scpromise = SitesConf.init();
|
|
||||||
var kbpromise = Keybinds.init();
|
|
||||||
|
|
||||||
// reset current css stuff in GlobalVars
|
// za sporočilca poslušamo v vsakem primeru, tudi če je razširitev na spletnem mestu onemogočena
|
||||||
GlobalVars.correctedVideoDimensions.top = null;
|
// we listen for messages in any case, even if extension is disabled on current site.
|
||||||
GlobalVars.correctedVideoDimensions.left = null;
|
browser.runtime.onMessage.addListener(receiveMessage);
|
||||||
GlobalVars.correctedVideoDimensions.width = null;
|
|
||||||
GlobalVars.correctedVideoDimensions.height = null;
|
|
||||||
|
|
||||||
GlobalVars.currentCss = {top: null, left: null};
|
await SitesConf.init();
|
||||||
|
// če je trenutno mesto onemogočeno, potem zaključimo na tem mestu
|
||||||
// počakamo, da so nastavitve naložene
|
// if current site is disabled, we quit here
|
||||||
// wait for settings to load
|
|
||||||
await scpromise;
|
|
||||||
await kbpromise;
|
|
||||||
|
|
||||||
// globalVars: lastAr type = original
|
|
||||||
GlobalVars.lastAr = {type: "original"};
|
|
||||||
|
|
||||||
if(Debug.debug)
|
|
||||||
console.log("[uw::main] configuration should be loaded now");
|
|
||||||
// start autoar and setup everything
|
|
||||||
|
|
||||||
|
|
||||||
if(Debug.debug)
|
|
||||||
console.log("[uw::main] | document is ready. Starting ar script ...");
|
|
||||||
|
|
||||||
if(! SitesConf.isEnabled(window.location.hostname)){
|
if(! SitesConf.isEnabled(window.location.hostname)){
|
||||||
if(Debug.debug)
|
if(Debug.debug)
|
||||||
@ -65,35 +37,39 @@ async function main(){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if(SitesConf.isArEnabled(window.location.hostname)){
|
|
||||||
|
|
||||||
|
await Keybinds.init();
|
||||||
|
|
||||||
|
if(Debug.debug)
|
||||||
|
console.log("[uw::main] configuration should be loaded now");
|
||||||
|
|
||||||
|
|
||||||
|
// setup the extension
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
var pageInfo;
|
||||||
|
|
||||||
|
async function setup(){
|
||||||
|
|
||||||
|
pageInfo = new PageInfo();
|
||||||
|
|
||||||
|
if(Debug.debug){
|
||||||
|
console.log("[uw.js::setup] pageInfo initialized. Here's the object:", pageInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if(ExtensionConf.arDetect.mode == "blacklist"){
|
||||||
// if(Debug.debug)
|
// if(Debug.debug)
|
||||||
// console.log("[uw::main] Aspect ratio detection is enabled. Starting ArDetect");
|
// console.log("[uw::main] Aspect ratio detection is enabled (mode=",ExtensionConf.arDetect.mode,"). Starting ArDetect");
|
||||||
// ArDetect.arSetup();
|
// ArDetect.arSetup();
|
||||||
// }
|
// }
|
||||||
// console.log("[uw::main] ExtensionConf:", ExtensionConf);
|
// else{
|
||||||
|
// if(Debug.debug)
|
||||||
|
// console.log("[uw::main] Aspect ratio detection is disabled. Mode:", ExtensionConf.arDetect.mode);
|
||||||
|
// }
|
||||||
|
|
||||||
if(ExtensionConf.arDetect.mode == "blacklist"){
|
|
||||||
if(Debug.debug)
|
|
||||||
console.log("[uw::main] Aspect ratio detection is enabled (mode=",ExtensionConf.arDetect.mode,"). Starting ArDetect");
|
|
||||||
ArDetect.arSetup();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if(Debug.debug)
|
|
||||||
console.log("[uw::main] Aspect ratio detection is disabled. Mode:", ExtensionConf.arDetect.mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener(receiveMessage);
|
|
||||||
setInterval( ghettoOnChange, 100);
|
|
||||||
setInterval( ghettoUrlWatcher, 500);
|
|
||||||
|
|
||||||
// ko se na ticevki zamenja video, console.log pravi da ultrawidify spremeni razmerje stranic. preglej element
|
|
||||||
// in pogled na predvajalnik pravita, da se to ni zgodilo. Iz tega sledi, da nam ticevka povozi css, ki smo ga
|
|
||||||
// vsilili. To super duper ni kul, zato uvedemo nekaj protiukrepov.
|
|
||||||
//
|
|
||||||
// when you change a video on youtube, console.log says that ultrawidify changes aspect ratio. inspect element
|
|
||||||
// and a look at youtube player, on the other hand, say this didn't happen. It seems that youtube overrides our
|
|
||||||
// css, and this is super duper uncool. Therefore, extra checks and measures.
|
|
||||||
setInterval( Resizer.antiCssOverride, 200);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,5 +248,5 @@ function receiveMessage(message, sender, sendResponse) {
|
|||||||
|
|
||||||
|
|
||||||
// $(document).ready(function() {
|
// $(document).ready(function() {
|
||||||
main();
|
init();
|
||||||
// });
|
// });
|
||||||
|
Loading…
Reference in New Issue
Block a user