1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-06-07 20:34:08 +02:00

Let JS continue even if jQuery or bridge objects are missing

This commit is contained in:
chylex 2020-06-05 08:27:35 +02:00
parent 1991f7f50f
commit e94e3cecf8
5 changed files with 49 additions and 15 deletions

View File

@ -1,4 +1,16 @@
(function($TD, $TDX, $, TD){ (function($, TD){
if ($ === null){
console.error("Missing jQuery");
}
if (!("$TD" in window)){
console.error("Missing $TD");
}
if (!("$TDX" in window)){
console.error("Missing $TDX");
}
// //
// Variable: Array of functions called after the website app is loaded. // Variable: Array of functions called after the website app is loaded.
// //
@ -54,6 +66,18 @@
}; };
}; };
//
// Function: Triggers an internal debug crash when something is missing.
//
const crashDebug = function(message){
if ("$TD" in window){
$TD.crashDebug(message);
}
else{
console.error(message);
}
}
// //
// Function: Returns true if an object has a specified property, otherwise returns false with a debug-only error message. // Function: Returns true if an object has a specified property, otherwise returns false with a debug-only error message.
// //
@ -61,7 +85,7 @@
for(let index = 0; index < chain.length; index++){ for(let index = 0; index < chain.length; index++){
if (!obj.hasOwnProperty(chain[index])){ if (!obj.hasOwnProperty(chain[index])){
debugger; debugger;
$TD.crashDebug("Missing property "+chain[index]+" in chain [obj]."+chain.join(".")); crashDebug("Missing property " + chain[index] + " in chain [obj]." + chain.join("."));
return false; return false;
} }
@ -79,7 +103,7 @@
if (!result.length){ if (!result.length){
debugger; debugger;
$TD.crashDebug("No elements were found for selector "+selector); crashDebug("No elements were found for selector "+selector);
} }
return result; return result;
@ -95,7 +119,7 @@
console.error(err); console.error(err);
debugger; debugger;
$TD.crashDebug("Caught error in function "+func.name) crashDebug("Caught error in function "+func.name)
fail && fail(); fail && fail();
} }
@ -1234,14 +1258,14 @@
let prev = TD.mustaches && TD.mustaches[name]; let prev = TD.mustaches && TD.mustaches[name];
if (!prev){ if (!prev){
$TD.crashDebug("Mustache injection is referencing an invalid mustache: "+name); crashDebug("Mustache injection is referencing an invalid mustache: "+name);
return false; return false;
} }
TD.mustaches[name] = prev.replace(search, replacement); TD.mustaches[name] = prev.replace(search, replacement);
if (prev === TD.mustaches[name]){ if (prev === TD.mustaches[name]){
$TD.crashDebug("Mustache injection had no effect: "+name); crashDebug("Mustache injection had no effect: "+name);
return false; return false;
} }
@ -1823,4 +1847,4 @@
location.href = "https://twitter.com/login?hide_message=true&redirect_after_login=https%3A%2F%2Ftweetdeck.twitter.com%2F%3Fvia_twitter_login%3Dtrue"; location.href = "https://twitter.com/login?hide_message=true&redirect_after_login=https%3A%2F%2Ftweetdeck.twitter.com%2F%3Fvia_twitter_login%3Dtrue";
}; };
} }
})($TD, $TDX, window.$, window.TD || {}); })(window.$ || null, window.TD || {});

View File

@ -1,4 +1,8 @@
(function($TDP){ (function(){
if (!("$TDP" in window)){
console.error("Missing $TDP");
}
// //
// Block: Setup a simple JavaScript object configuration loader. // Block: Setup a simple JavaScript object configuration loader.
// //
@ -49,4 +53,4 @@
element: element element: element
}; };
}; };
})($TDP); })();

View File

@ -1,4 +1,4 @@
(function($, $TD){ (function(){
$(document).one("TD.ready", function(){ $(document).one("TD.ready", function(){
let css = $(`<style>#import "styles/introduction.css"</style>`).appendTo(document.head); let css = $(`<style>#import "styles/introduction.css"</style>`).appendTo(document.head);
let ele = $(`#import "markup/introduction.html"`).appendTo(".js-app"); let ele = $(`#import "markup/introduction.html"`).appendTo(".js-app");
@ -38,4 +38,4 @@
}); });
}); });
}); });
})($, $TD); })();

View File

@ -1,4 +1,4 @@
(function($TD, $TDX){ (function(){
// //
// Variable: Collection of all <a> tags. // Variable: Collection of all <a> tags.
// //
@ -181,4 +181,4 @@
// Block: Force a reset of scroll position on every load. // Block: Force a reset of scroll position on every load.
// //
history.scrollRestoration = "manual"; history.scrollRestoration = "manual";
})($TD, $TDX); })();

View File

@ -1,4 +1,9 @@
(function($TDU){ (function(){
if (!("$TDU" in window)){
console.error("Missing $TDU");
return;
}
// //
// Function: Creates the update notification element. Removes the old one if already exists. // Function: Creates the update notification element. Removes the old one if already exists.
// //
@ -140,6 +145,7 @@
$(document).one("TD.ready", triggerCheck); $(document).one("TD.ready", triggerCheck);
}catch(err){ }catch(err){
console.warn("Missing jQuery or TD.ready event");
setTimeout(triggerCheck, 500); setTimeout(triggerCheck, 500);
} }
@ -147,4 +153,4 @@
// Block: Setup global functions. // Block: Setup global functions.
// //
window.TDUF_displayNotification = displayNotification; window.TDUF_displayNotification = displayNotification;
})($TDU); })();