Improved planex display

This commit is contained in:
keplyx 2020-01-31 12:14:38 +01:00
parent e72196812e
commit 628f36df24

View file

@ -18,22 +18,27 @@ const CUSTOM_CSS_NIGHTMODE = 'https://srv-falcon.etud.insa-toulouse.fr/~amicale_
// // JS + JQuery functions used to remove alpha from events. Copy paste in browser console for quick testing // // JS + JQuery functions used to remove alpha from events. Copy paste in browser console for quick testing
// // Remove alpha from given Jquery node // // Remove alpha from given Jquery node
// function removeAlpha(node) { // function removeAlpha(node) {
// console.log(node);
// let bg = node.css("background-color"); // let bg = node.css("background-color");
// if (bg.match("^rgba")) { // if (bg.match("^rgba")) {
// let a = bg.slice(5).split(','); // let a = bg.slice(5).split(',');
// let newBg ='rgb(' + a[0] + ',' + parseInt(a[1]) + ',' + parseInt(a[2]) + ')'; // // Fix for tooltips with broken background
// if (parseInt(a[0]) === parseInt(a[1]) && parseInt(a[1]) === parseInt(a[2]) && parseInt(a[2]) === 0) {
// a[0] = a[1] = a[2] = '255';
// }
// let newBg ='rgb(' + a[0] + ',' + a[1] + ',' + a[2] + ')';
// node.css("background-color", newBg); // node.css("background-color", newBg);
// } // }
// } // }
// // Observe for planning DOM changes // // Observe for planning DOM changes
// let observer = new MutationObserver(function(mutations) { // let observer = new MutationObserver(function(mutations) {
// for (let i = 0; i < mutations.length; i++) { // for (let i = 0; i < mutations.length; i++) {
// if (mutations[i]['addedNodes'].length > 0 && $(mutations[i]['addedNodes'][0]).hasClass("fc-event")) // if (mutations[i]['addedNodes'].length > 0 &&
// ($(mutations[i]['addedNodes'][0]).hasClass("fc-event") || $(mutations[i]['addedNodes'][0]).hasClass("tooltiptopicevent")))
// removeAlpha($(mutations[i]['addedNodes'][0])) // removeAlpha($(mutations[i]['addedNodes'][0]))
// } // }
// }); // });
// observer.observe(document.querySelector(".fc-body"), {attributes: false, childList: true, characterData: false, subtree:true}); // // observer.observe(document.querySelector(".fc-body"), {attributes: false, childList: true, characterData: false, subtree:true});
// observer.observe(document.querySelector("body"), {attributes: false, childList: true, characterData: false, subtree:true});
// // Run remove alpha a first time on whole planning. Useful when code injected after planning fully loaded. // // Run remove alpha a first time on whole planning. Useful when code injected after planning fully loaded.
// $(".fc-event-container .fc-event").each(function(index) { // $(".fc-event-container .fc-event").each(function(index) {
// removeAlpha($(this)); // removeAlpha($(this));
@ -42,21 +47,28 @@ const CUSTOM_CSS_NIGHTMODE = 'https://srv-falcon.etud.insa-toulouse.fr/~amicale_
// Watch for changes in the calendar and call the remove alpha function // Watch for changes in the calendar and call the remove alpha function
const OBSERVE_MUTATIONS_INJECTED = const OBSERVE_MUTATIONS_INJECTED =
'function removeAlpha(node) {\n' + 'function removeAlpha(node) {\n' +
' console.log(node);\n' +
' let bg = node.css("background-color");\n' + ' let bg = node.css("background-color");\n' +
' if (bg.match("^rgba")) {\n' + ' if (bg.match("^rgba")) {\n' +
' let a = bg.slice(5).split(\',\');\n' + ' let a = bg.slice(5).split(\',\');\n' +
' let newBg =\'rgb(\' + a[0] + \',\' + parseInt(a[1]) + \',\' + parseInt(a[2]) + \')\';\n' + ' // Fix for tooltips with broken background\n' +
' if (parseInt(a[0]) === parseInt(a[1]) && parseInt(a[1]) === parseInt(a[2]) && parseInt(a[2]) === 0) {\n' +
' a[0] = a[1] = a[2] = \'255\';\n' +
' }\n' +
' let newBg =\'rgb(\' + a[0] + \',\' + a[1] + \',\' + a[2] + \')\';\n' +
' node.css("background-color", newBg);\n' + ' node.css("background-color", newBg);\n' +
' }\n' + ' }\n' +
'}' + '}\n' +
'// Observe for planning DOM changes\n' +
'let observer = new MutationObserver(function(mutations) {\n' + 'let observer = new MutationObserver(function(mutations) {\n' +
' for (let i = 0; i < mutations.length; i++) {\n' + ' for (let i = 0; i < mutations.length; i++) {\n' +
' if (mutations[i][\'addedNodes\'].length > 0 && $(mutations[i][\'addedNodes\'][0]).hasClass("fc-event"))\n' + ' if (mutations[i][\'addedNodes\'].length > 0 &&\n' +
' ($(mutations[i][\'addedNodes\'][0]).hasClass("fc-event") || $(mutations[i][\'addedNodes\'][0]).hasClass("tooltiptopicevent")))\n' +
' removeAlpha($(mutations[i][\'addedNodes\'][0]))\n' + ' removeAlpha($(mutations[i][\'addedNodes\'][0]))\n' +
' }\n' + ' }\n' +
'});\n' + '});\n' +
'observer.observe(document.querySelector(".fc-body"), {attributes: false, childList: true, characterData: false, subtree:true});\n' + '// observer.observe(document.querySelector(".fc-body"), {attributes: false, childList: true, characterData: false, subtree:true});\n' +
'observer.observe(document.querySelector("body"), {attributes: false, childList: true, characterData: false, subtree:true});\n' +
'// Run remove alpha a first time on whole planning. Useful when code injected after planning fully loaded.\n' +
'$(".fc-event-container .fc-event").each(function(index) {\n' + '$(".fc-event-container .fc-event").each(function(index) {\n' +
' removeAlpha($(this));\n' + ' removeAlpha($(this));\n' +
'});'; '});';
@ -73,17 +85,13 @@ export default class PlanexScreen extends React.Component<Props> {
this.customInjectedJS = this.customInjectedJS =
'$(document).ready(function() {' + '$(document).ready(function() {' +
OBSERVE_MUTATIONS_INJECTED + OBSERVE_MUTATIONS_INJECTED +
'$("head").append(\'<meta name="viewport" content="width=device-width, initial-scale=0.7">\');' + '$("head").append(\'<meta name="viewport" content="width=device-width, initial-scale=0.9">\');' +
'$("head").append(\'<link rel="stylesheet" href="' + CUSTOM_CSS_GENERAL + '" type="text/css"/>\');'; '$("head").append(\'<link rel="stylesheet" href="' + CUSTOM_CSS_GENERAL + '" type="text/css"/>\');';
if (ThemeManager.getNightMode()) if (ThemeManager.getNightMode())
this.customInjectedJS += '$("head").append(\'<link rel="stylesheet" href="' + CUSTOM_CSS_NIGHTMODE + '" type="text/css"/>\');'; this.customInjectedJS += '$("head").append(\'<link rel="stylesheet" href="' + CUSTOM_CSS_NIGHTMODE + '" type="text/css"/>\');';
this.customInjectedJS += this.customInjectedJS +=
'$(".fc-toolbar .fc-center").append(\'<p id="rotateToLandscape" style="color: ' + ThemeManager.getCurrentThemeVariables().brandPrimary + '">' +
i18n.t("planexScreen.rotateToLandscape") + '</p>\');' +
'$(".fc-toolbar .fc-center").append(\'<p id="rotateToPortrait" style="color: ' + ThemeManager.getCurrentThemeVariables().brandPrimary + '">' +
i18n.t("planexScreen.rotateToPortrait") + '</p>\');' +
'removeAlpha();' + 'removeAlpha();' +
'});true;'; // Prevent crash on ios '});true;'; // Prevent crash on ios