From cb5efc2e1ac7149fff93287d7bd2aba536f1465e Mon Sep 17 00:00:00 2001 From: MysticJay Date: Sat, 15 May 2021 18:33:29 +0200 Subject: [PATCH 01/14] namespace nomalize namespace definition remove all namespce occurences add esxposed secition to top --- plugins/link-show-direction.js | 85 +++++++++++++++------------- plugins/periodic-refresh.js | 13 ++--- plugins/scroll-wheel-zoom-disable.js | 6 +- 3 files changed, 54 insertions(+), 50 deletions(-) diff --git a/plugins/link-show-direction.js b/plugins/link-show-direction.js index 021e05f3a..ba41fc639 100644 --- a/plugins/link-show-direction.js +++ b/plugins/link-show-direction.js @@ -6,12 +6,17 @@ // use own namespace for plugin -window.plugin.linkShowDirection = function() {}; -window.plugin.linkShowDirection.ANIMATE_UPDATE_TIME = 1000; // 1000ms = 1s +var linkShowDirection = {}; +window.plugin.linkShowDirection = linkShowDirection; + +// exposed +window.plugin.linkShowDirection.showDialog = showDialog; + +var ANIMATE_UPDATE_TIME = 1000; // 1000ms = 1s // Hack: // 100000 - a large enough number to be the equivalent of 100%, which is not supported Leaflet when displaying with canvas -window.plugin.linkShowDirection.styles = { +var styles = { 'Disabled': [null], 'Static *': [ '30,5,15,5,15,5,2,5,2,5,2,5,2,5,30,0', @@ -34,22 +39,22 @@ window.plugin.linkShowDirection.styles = { '2,6,4,6,4,6,2,0', ], }; -window.plugin.linkShowDirection.dashArray = null; -window.plugin.linkShowDirection.frame = 0; -window.plugin.linkShowDirection.moving = false; +var dashArray = null; +var activeFrame = 0; +var moving = false; -window.plugin.linkShowDirection.animateLinks = function() { - var frames = window.plugin.linkShowDirection.styles[window.plugin.linkShowDirection.mode]; +var animateLinks = function() { + var frames = styles[mode]; if(!frames) frames = [null]; - if(!window.plugin.linkShowDirection.moving) { - var frame = window.plugin.linkShowDirection.frame; + if(!moving) { + var frame = activeFrame; frame = (frame + 1) % frames.length; - window.plugin.linkShowDirection.frame = frame; + activeFrame = frame; - window.plugin.linkShowDirection.dashArray = frames[frame]; - window.plugin.linkShowDirection.addAllLinkStyles(); + dashArray = frames[frame]; + addAllLinkStyles(); } if(frames.length < 2) return; // no animation needed @@ -60,31 +65,31 @@ window.plugin.linkShowDirection.animateLinks = function() { // this would mean the user has no chance to interact with IITC // to prevent this, create a short timer that then sets the timer for the next frame. if the browser is slow to render, // the short timer should fire later, at which point the desired ANIMATE_UPDATE_TIME timer is started - clearTimeout(window.plugin.linkShowDirection.timer); - window.plugin.linkShowDirection.timer = setTimeout(function() { - clearTimeout(window.plugin.linkShowDirection.timer); - window.plugin.linkShowDirection.timer = setTimeout( - window.plugin.linkShowDirection.animateLinks, - window.plugin.linkShowDirection.ANIMATE_UPDATE_TIME); + clearTimeout(timer); + var timer = setTimeout(function() { + clearTimeout(timer); + timer = setTimeout( + animateLinks, + ANIMATE_UPDATE_TIME); }, 10); }; -window.plugin.linkShowDirection.addAllLinkStyles = function() { - $.each(links,function(guid,link) { window.plugin.linkShowDirection.addLinkStyle(link); }); +var addAllLinkStyles = function() { + $.each(links,function(guid,link) { addLinkStyle(link); }); if(window.plugin.drawTools && localStorage['plugin-linkshowdirection-drawtools'] == "true") { window.plugin.drawTools.drawnItems.eachLayer(function(layer) { if(layer instanceof L.GeodesicPolyline) - window.plugin.linkShowDirection.addLinkStyle(layer); + addLinkStyle(layer); }); } }; -window.plugin.linkShowDirection.addLinkStyle = function(link) { - link.setStyle({dashArray: window.plugin.linkShowDirection.dashArray}); +var addLinkStyle = function(link) { + link.setStyle({dashArray: dashArray}); }; -window.plugin.linkShowDirection.removeDrawToolsStyle = function() { +var removeDrawToolsStyle = function() { if(!window.plugin.drawTools) return; window.plugin.drawTools.drawnItems.eachLayer(function(layer) { @@ -93,23 +98,23 @@ window.plugin.linkShowDirection.removeDrawToolsStyle = function() { }); }; -window.plugin.linkShowDirection.showDialog = function() { +function showDialog () { var div = document.createElement('div'); - $.each(window.plugin.linkShowDirection.styles, function(style) { + $.each(styles, function(style) { var label = div.appendChild(document.createElement('label')); var input = label.appendChild(document.createElement('input')); input.type = 'radio'; input.name = 'plugin-link-show-direction'; input.value = style; - if(style == window.plugin.linkShowDirection.mode) { + if(style == mode) { input.checked = true; } input.addEventListener('click', function() { - window.plugin.linkShowDirection.mode = style; + mode = style; localStorage['plugin-linkshowdirection-mode'] = style; - window.plugin.linkShowDirection.animateLinks(); + animateLinks(); }, false); label.appendChild(document.createTextNode(' ' + style)); @@ -133,9 +138,9 @@ window.plugin.linkShowDirection.showDialog = function() { localStorage['plugin-linkshowdirection-drawtools'] = input.checked.toString(); if(input.checked) - window.plugin.linkShowDirection.animateLinks(); + animateLinks(); else - window.plugin.linkShowDirection.removeDrawToolsStyle(); + removeDrawToolsStyle(); }, false); label.appendChild(document.createTextNode(' Apply to DrawTools')); @@ -148,23 +153,23 @@ window.plugin.linkShowDirection.showDialog = function() { }); }; -window.plugin.linkShowDirection.setup = function() { +linkShowDirection.setup = function() { $('#toolbox').append(' LinkDirection Opt'); - addHook('linkAdded', function(data) { window.plugin.linkShowDirection.addLinkStyle(data.link); }); + addHook('linkAdded', function(data) { addLinkStyle(data.link); }); try { - window.plugin.linkShowDirection.mode = localStorage['plugin-linkshowdirection-mode']; + mode = localStorage['plugin-linkshowdirection-mode']; } catch(e) { console.warn(e); - window.plugin.linkShowDirection.mode = 'Disabled'; + mode = 'Disabled'; } - window.plugin.linkShowDirection.animateLinks(); + animateLinks(); // set up move start/end handlers to pause animations while moving - map.on('movestart', function() { window.plugin.linkShowDirection.moving = true; }); - map.on('moveend', function() { window.plugin.linkShowDirection.moving = false; }); + map.on('movestart', function() { moving = true; }); + map.on('moveend', function() { moving = false; }); }; -var setup = window.plugin.linkShowDirection.setup; +var setup = linkShowDirection.setup; diff --git a/plugins/periodic-refresh.js b/plugins/periodic-refresh.js index d0b2dd39c..0cfa01848 100644 --- a/plugins/periodic-refresh.js +++ b/plugins/periodic-refresh.js @@ -4,21 +4,20 @@ // @version 0.1.0 // @description For use for unattended display screens only, this plugin causes idle mode to be left once per hour. +// use own namespace for plugin +var periodicRefresh = {}; +window.plugin.periodicRefresh = periodicRefresh; -window.plugin.periodicRefresh = function() {}; - -window.plugin.periodicRefresh.wakeup = function() { +var wakeup = function() { console.log('periodicRefresh: timer fired - leaving idle mode'); idleReset(); } -window.plugin.periodicRefresh.setup = function() { +var setup = function() { var refreshMinutes = 60; - setInterval ( window.plugin.periodicRefresh.wakeup, refreshMinutes*60*1000 ); + setInterval (wakeup, refreshMinutes*60*1000 ); }; - -var setup = window.plugin.periodicRefresh.setup; diff --git a/plugins/scroll-wheel-zoom-disable.js b/plugins/scroll-wheel-zoom-disable.js index bd5b78b06..ab15a7732 100644 --- a/plugins/scroll-wheel-zoom-disable.js +++ b/plugins/scroll-wheel-zoom-disable.js @@ -6,12 +6,12 @@ // use own namespace for plugin -window.plugin.scrollWheelZoomDisable = function() {}; +// var scrollWheelZoomDisable = {}; +// window.plugin.scrollWheelZoomDisable = scrollWheelZoomDisable; -window.plugin.scrollWheelZoomDisable.setup = function() { +var setup = function() { window.map.scrollWheelZoom.disable(); }; -var setup = window.plugin.scrollWheelZoomDisable.setup; From 8580309eaf916060df9322867e5361cf07fd9789 Mon Sep 17 00:00:00 2001 From: MysticJay Date: Sun, 16 May 2021 17:47:24 +0200 Subject: [PATCH 02/14] ESLINT changing code to match eslint rules. function definition syntax Version bump --- plugins/fix-china-map-offset.js | 2 + plugins/link-show-direction.js | 75 +++++++++++++++------------- plugins/periodic-refresh.js | 14 +++--- plugins/scroll-wheel-zoom-disable.js | 12 ++--- 4 files changed, 51 insertions(+), 52 deletions(-) diff --git a/plugins/fix-china-map-offset.js b/plugins/fix-china-map-offset.js index 047a053ae..8c9a91234 100644 --- a/plugins/fix-china-map-offset.js +++ b/plugins/fix-china-map-offset.js @@ -5,6 +5,8 @@ // @description Show correct maps for China user by applying offset tweaks. +/* exported setup --eslint */ +/* global L */ // use own namespace for plugin var fixChinaMapOffset = {}; window.plugin.fixChinaMapOffset = fixChinaMapOffset; diff --git a/plugins/link-show-direction.js b/plugins/link-show-direction.js index ba41fc639..2b4944780 100644 --- a/plugins/link-show-direction.js +++ b/plugins/link-show-direction.js @@ -1,16 +1,18 @@ // @author jonatkins // @name Direction of links on map // @category Tweaks -// @version 0.2.1 +// @version 0.2.2 // @description Show the direction of links on the map by adding short dashes to the line at the origin portal. +/* exported setup --eslint */ +/* global L, dialog, addHook, map, links */ // use own namespace for plugin var linkShowDirection = {}; window.plugin.linkShowDirection = linkShowDirection; // exposed -window.plugin.linkShowDirection.showDialog = showDialog; +// linkShowDirection.showDialog = showDialog; var ANIMATE_UPDATE_TIME = 1000; // 1000ms = 1s @@ -37,18 +39,19 @@ var styles = { '0,4,4,6,4,6,4,2', '0,6,4,6,4,6,4,0', '2,6,4,6,4,6,2,0', - ], + ] }; var dashArray = null; var activeFrame = 0; var moving = false; +var activeStyle = ''; -var animateLinks = function() { - var frames = styles[mode]; - if(!frames) frames = [null]; +function animateLinks () { + var frames = styles[activeStyle]; + if (!frames) frames = [null]; - if(!moving) { + if (!moving) { var frame = activeFrame; frame = (frame + 1) % frames.length; activeFrame = frame; @@ -57,7 +60,7 @@ var animateLinks = function() { addAllLinkStyles(); } - if(frames.length < 2) return; // no animation needed + if (frames.length < 2) return; // no animation needed // browsers don't render the SVG style changes until after the timer function has finished. // this means if we start the next timeout in here a lot of the delay time will be taken by the browser itself @@ -72,33 +75,35 @@ var animateLinks = function() { animateLinks, ANIMATE_UPDATE_TIME); }, 10); -}; +} -var addAllLinkStyles = function() { +function addAllLinkStyles () { $.each(links,function(guid,link) { addLinkStyle(link); }); - if(window.plugin.drawTools && localStorage['plugin-linkshowdirection-drawtools'] == "true") { + if (window.plugin.drawTools && localStorage['plugin-linkshowdirection-drawtools'] === 'true') { window.plugin.drawTools.drawnItems.eachLayer(function(layer) { - if(layer instanceof L.GeodesicPolyline) + if (layer instanceof L.GeodesicPolyline) { addLinkStyle(layer); + } }); } -}; +} -var addLinkStyle = function(link) { +function addLinkStyle (link) { link.setStyle({dashArray: dashArray}); -}; +} -var removeDrawToolsStyle = function() { - if(!window.plugin.drawTools) return; +function removeDrawToolsStyle () { + if (!window.plugin.drawTools) return; window.plugin.drawTools.drawnItems.eachLayer(function(layer) { - if(layer instanceof L.GeodesicPolyline) + if (layer instanceof L.GeodesicPolyline) { layer.setStyle({dashArray: null}); + } }); -}; +} -function showDialog () { +var showDialog = function () { var div = document.createElement('div'); $.each(styles, function(style) { @@ -107,12 +112,12 @@ function showDialog () { input.type = 'radio'; input.name = 'plugin-link-show-direction'; input.value = style; - if(style == mode) { + if (style === activeStyle) { input.checked = true; } input.addEventListener('click', function() { - mode = style; + activeStyle = style; localStorage['plugin-linkshowdirection-mode'] = style; animateLinks(); }, false); @@ -126,21 +131,22 @@ function showDialog () { ' * Static: six segments will indicate each link\'s direction. ' + 'Two long segments are on the origin\'s side, follow by four short segments on the destination\'s side.')); - if(window.plugin.drawTools) { + if (window.plugin.drawTools) { div.appendChild(document.createElement('br')); var label = div.appendChild(document.createElement('label')); var input = label.appendChild(document.createElement('input')); input.type = 'checkbox'; - input.checked = localStorage['plugin-linkshowdirection-drawtools'] == "true"; + input.checked = localStorage['plugin-linkshowdirection-drawtools'] === 'true'; input.addEventListener('click', function() { localStorage['plugin-linkshowdirection-drawtools'] = input.checked.toString(); - - if(input.checked) + + if (input.checked) { animateLinks(); - else + } else { removeDrawToolsStyle(); + } }, false); label.appendChild(document.createTextNode(' Apply to DrawTools')); @@ -153,16 +159,15 @@ function showDialog () { }); }; -linkShowDirection.setup = function() { - $('#toolbox').append(' LinkDirection Opt'); - +function setup () { + $('#toolbox').append(' LinkDirection Opt').on('click', showDialog); addHook('linkAdded', function(data) { addLinkStyle(data.link); }); try { - mode = localStorage['plugin-linkshowdirection-mode']; - } catch(e) { + activeStyle = localStorage['plugin-linkshowdirection-mode']; + } catch (e) { console.warn(e); - mode = 'Disabled'; + activeStyle = 'Disabled'; } animateLinks(); @@ -170,6 +175,4 @@ linkShowDirection.setup = function() { // set up move start/end handlers to pause animations while moving map.on('movestart', function() { moving = true; }); map.on('moveend', function() { moving = false; }); -}; - -var setup = linkShowDirection.setup; +} diff --git a/plugins/periodic-refresh.js b/plugins/periodic-refresh.js index 0cfa01848..c18a92a7d 100644 --- a/plugins/periodic-refresh.js +++ b/plugins/periodic-refresh.js @@ -1,23 +1,21 @@ // @author jonatkins // @name Periodic refresh // @category Tweaks -// @version 0.1.0 +// @version 0.1.1 // @description For use for unattended display screens only, this plugin causes idle mode to be left once per hour. +/* exported setup --eslint */ +/* global idleReset */ // use own namespace for plugin var periodicRefresh = {}; window.plugin.periodicRefresh = periodicRefresh; -var wakeup = function() { +function wakeup () { console.log('periodicRefresh: timer fired - leaving idle mode'); idleReset(); } - -var setup = function() { - +function setup () { var refreshMinutes = 60; - setInterval (wakeup, refreshMinutes*60*1000 ); - -}; +} diff --git a/plugins/scroll-wheel-zoom-disable.js b/plugins/scroll-wheel-zoom-disable.js index ab15a7732..44752465f 100644 --- a/plugins/scroll-wheel-zoom-disable.js +++ b/plugins/scroll-wheel-zoom-disable.js @@ -1,17 +1,13 @@ // @author jonatkins // @name Disable mouse wheel zoom // @category Tweaks -// @version 0.1.0 +// @version 0.1.1 // @description Disable the use of mouse wheel to zoom. The map zoom controls or keyboard are still available. - +/* exported setup --eslint */ // use own namespace for plugin -// var scrollWheelZoomDisable = {}; -// window.plugin.scrollWheelZoomDisable = scrollWheelZoomDisable; - -var setup = function() { +function setup () { window.map.scrollWheelZoom.disable(); - -}; +} From cd995c52b01a50d6fee77c649870e9f49cf7187f Mon Sep 17 00:00:00 2001 From: MysticJay Date: Tue, 26 Jul 2022 13:55:11 +0200 Subject: [PATCH 03/14] GIT Comments resolving GIT proposals --- plugins/link-show-direction.js | 7 +++---- plugins/scroll-wheel-zoom-disable.js | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/plugins/link-show-direction.js b/plugins/link-show-direction.js index 2b4944780..8464af3be 100644 --- a/plugins/link-show-direction.js +++ b/plugins/link-show-direction.js @@ -10,15 +10,14 @@ // use own namespace for plugin var linkShowDirection = {}; window.plugin.linkShowDirection = linkShowDirection; - -// exposed -// linkShowDirection.showDialog = showDialog; +var styles = {}; +linkShowDirection.styles = styles; var ANIMATE_UPDATE_TIME = 1000; // 1000ms = 1s // Hack: // 100000 - a large enough number to be the equivalent of 100%, which is not supported Leaflet when displaying with canvas -var styles = { +styles = { 'Disabled': [null], 'Static *': [ '30,5,15,5,15,5,2,5,2,5,2,5,2,5,30,0', diff --git a/plugins/scroll-wheel-zoom-disable.js b/plugins/scroll-wheel-zoom-disable.js index 44752465f..63bbae7f1 100644 --- a/plugins/scroll-wheel-zoom-disable.js +++ b/plugins/scroll-wheel-zoom-disable.js @@ -5,7 +5,6 @@ // @description Disable the use of mouse wheel to zoom. The map zoom controls or keyboard are still available. /* exported setup --eslint */ -// use own namespace for plugin function setup () { window.map.scrollWheelZoom.disable(); From 14ba2227535747286f782d95806c59d00b98e6c1 Mon Sep 17 00:00:00 2001 From: MysticJay Date: Tue, 26 Jul 2022 17:51:00 +0200 Subject: [PATCH 04/14] Toolbox entry fixed fixed onclick. --- plugins/link-show-direction.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/link-show-direction.js b/plugins/link-show-direction.js index 8464af3be..73bb1bac1 100644 --- a/plugins/link-show-direction.js +++ b/plugins/link-show-direction.js @@ -102,7 +102,7 @@ function removeDrawToolsStyle () { }); } -var showDialog = function () { +linkShowDirection.showDialog = function () { var div = document.createElement('div'); $.each(styles, function(style) { @@ -159,7 +159,8 @@ var showDialog = function () { }; function setup () { - $('#toolbox').append(' LinkDirection Opt').on('click', showDialog); + $('#toolbox').append('LinkDirection Opt'); + addHook('linkAdded', function(data) { addLinkStyle(data.link); }); try { From 035a8a3de412065a8942f0c5c0b9e27eaa5bc34a Mon Sep 17 00:00:00 2001 From: MysticJay Date: Tue, 26 Jul 2022 17:57:50 +0200 Subject: [PATCH 05/14] Update periodic-refresh.js exposing refreshMinutes --- plugins/periodic-refresh.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/periodic-refresh.js b/plugins/periodic-refresh.js index c18a92a7d..e5a05c1bf 100644 --- a/plugins/periodic-refresh.js +++ b/plugins/periodic-refresh.js @@ -10,12 +10,13 @@ var periodicRefresh = {}; window.plugin.periodicRefresh = periodicRefresh; +periodicRefresh.refreshMinutes = 60; + function wakeup () { console.log('periodicRefresh: timer fired - leaving idle mode'); idleReset(); } function setup () { - var refreshMinutes = 60; - setInterval (wakeup, refreshMinutes*60*1000 ); + setInterval (wakeup, periodicRefresh.refreshMinutes*60*1000 ); } From 8a722e49408b77d4bddb09401dc7608a0c1beb0e Mon Sep 17 00:00:00 2001 From: MysticJay Date: Tue, 8 Aug 2023 23:33:53 +0200 Subject: [PATCH 06/14] Comments resolved exposed values need pluginnames, refernces do not work --- plugins/link-show-direction.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/plugins/link-show-direction.js b/plugins/link-show-direction.js index 73bb1bac1..83815f57b 100644 --- a/plugins/link-show-direction.js +++ b/plugins/link-show-direction.js @@ -10,14 +10,13 @@ // use own namespace for plugin var linkShowDirection = {}; window.plugin.linkShowDirection = linkShowDirection; -var styles = {}; -linkShowDirection.styles = styles; +linkShowDirection.timer = 0; var ANIMATE_UPDATE_TIME = 1000; // 1000ms = 1s // Hack: // 100000 - a large enough number to be the equivalent of 100%, which is not supported Leaflet when displaying with canvas -styles = { +linkShowDirection.styles = { 'Disabled': [null], 'Static *': [ '30,5,15,5,15,5,2,5,2,5,2,5,2,5,30,0', @@ -47,7 +46,7 @@ var activeStyle = ''; function animateLinks () { - var frames = styles[activeStyle]; + var frames = linkShowDirection.styles[activeStyle]; if (!frames) frames = [null]; if (!moving) { @@ -67,10 +66,10 @@ function animateLinks () { // this would mean the user has no chance to interact with IITC // to prevent this, create a short timer that then sets the timer for the next frame. if the browser is slow to render, // the short timer should fire later, at which point the desired ANIMATE_UPDATE_TIME timer is started - clearTimeout(timer); - var timer = setTimeout(function() { - clearTimeout(timer); - timer = setTimeout( + clearTimeout(linkShowDirection.timer); + linkShowDirection.timer = setTimeout(function() { + clearTimeout(linkShowDirection.timer); + linkShowDirection.timer = setTimeout( animateLinks, ANIMATE_UPDATE_TIME); }, 10); From fd2844c2e825ab44b049bd26c8b93534875bc7b9 Mon Sep 17 00:00:00 2001 From: MysticJay Date: Wed, 9 Aug 2023 00:18:38 +0200 Subject: [PATCH 07/14] eslint fixes --- plugins/fix-china-map-offset.js | 2 -- plugins/link-show-direction.js | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/plugins/fix-china-map-offset.js b/plugins/fix-china-map-offset.js index 8c9a91234..88138b9c8 100644 --- a/plugins/fix-china-map-offset.js +++ b/plugins/fix-china-map-offset.js @@ -4,7 +4,6 @@ // @version 0.3.1 // @description Show correct maps for China user by applying offset tweaks. - /* exported setup --eslint */ /* global L */ // use own namespace for plugin @@ -18,7 +17,6 @@ window.plugin.fixChinaMapOffset = fixChinaMapOffset; // // Example: basemap-gaode.user.js - // Before understanding how this plugin works, you should know 3 points: // // Point1. diff --git a/plugins/link-show-direction.js b/plugins/link-show-direction.js index 83815f57b..bd7b7f8e4 100644 --- a/plugins/link-show-direction.js +++ b/plugins/link-show-direction.js @@ -44,7 +44,6 @@ var activeFrame = 0; var moving = false; var activeStyle = ''; - function animateLinks () { var frames = linkShowDirection.styles[activeStyle]; if (!frames) frames = [null]; @@ -67,7 +66,7 @@ function animateLinks () { // to prevent this, create a short timer that then sets the timer for the next frame. if the browser is slow to render, // the short timer should fire later, at which point the desired ANIMATE_UPDATE_TIME timer is started clearTimeout(linkShowDirection.timer); - linkShowDirection.timer = setTimeout(function() { + linkShowDirection.timer = setTimeout(function () { clearTimeout(linkShowDirection.timer); linkShowDirection.timer = setTimeout( animateLinks, @@ -76,7 +75,7 @@ function animateLinks () { } function addAllLinkStyles () { - $.each(links,function(guid,link) { addLinkStyle(link); }); + $.each(links, function(guid,link) { addLinkStyle(link); }); if (window.plugin.drawTools && localStorage['plugin-linkshowdirection-drawtools'] === 'true') { window.plugin.drawTools.drawnItems.eachLayer(function(layer) { @@ -175,3 +174,4 @@ function setup () { map.on('movestart', function() { moving = true; }); map.on('moveend', function() { moving = false; }); } + From 1b3cc1c890309670131ace3382c3ad619567e5ad Mon Sep 17 00:00:00 2001 From: MysticJay Date: Wed, 9 Aug 2023 09:27:16 +0200 Subject: [PATCH 08/14] eslint/prittier files adjusted to the proposals. added pritter-ignore where needed --- .eslintrc.json | 6 ++- .prettierrc.json | 3 +- plugins/fix-china-map-offset.js | 37 +++++++------ plugins/link-show-direction.js | 95 +++++++++++++++++++-------------- plugins/periodic-refresh.js | 6 +-- 5 files changed, 87 insertions(+), 60 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index efa6c4ae0..36e3fab88 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,6 +18,10 @@ "rules": { "eqeqeq": "error", "spaced-comment": "error", - "no-unused-expressions": "error" + "no-unused-expressions": "error", + "linebreak-style": [ + "error", + "windows" + ] } } diff --git a/.prettierrc.json b/.prettierrc.json index 473a6802b..a1d1cad80 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -3,5 +3,6 @@ "trailingComma": "es5", "tabWidth": 2, "semi": true, - "singleQuote": true + "singleQuote": true, + "endOfLine":"auto" } diff --git a/plugins/fix-china-map-offset.js b/plugins/fix-china-map-offset.js index 88138b9c8..2f6261ceb 100644 --- a/plugins/fix-china-map-offset.js +++ b/plugins/fix-china-map-offset.js @@ -65,7 +65,8 @@ window.plugin.fixChinaMapOffset = fixChinaMapOffset; // https://github.com/Artoria2e5/PRCoords // (more info: https://github.com/iitc-project/ingress-intel-total-conversion/pull/1188) -var insane_is_in_china = (function () { // adapted from https://github.com/Artoria2e5/PRCoords/blob/master/js/misc/insane_is_in_china.js +// adapted from https://github.com/Artoria2e5/PRCoords/blob/master/js/misc/insane_is_in_china.js +var insane_is_in_china = (function () { /* eslint-disable */ 'use strict'; @@ -164,12 +165,13 @@ var insane_is_in_china = (function () { // adapted from https://github.com/Artor } return { isInChina: isInChina }; -/* eslint-enable */ + /* eslint-enable */ })(); fixChinaMapOffset.isInChina = insane_is_in_china.isInChina; -var PRCoords = (function () { // adapted from https://github.com/Artoria2e5/PRCoords/blob/master/js/PRCoords.js +// adapted from https://github.com/Artoria2e5/PRCoords/blob/master/js/PRCoords.js +var PRCoords = (function () { /* eslint-disable */ 'use strict'; @@ -212,7 +214,7 @@ var PRCoords = (function () { // adapted from https://github.com/Artoria2e5/PRCo } return { wgs_gcj: wgs_gcj }; -/* eslint-enable */ + /* eslint-enable */ })(); fixChinaMapOffset.wgs_gcj = PRCoords.wgs_gcj; @@ -221,12 +223,14 @@ fixChinaMapOffset.wgs_gcj = PRCoords.wgs_gcj; var fixChinaOffset = { _inChina: false, - _inChinaLastChecked: [0,0], + _inChinaLastChecked: [0, 0], _inChinaValidRadius: 100000, _isInChina: function (latlng) { - if (latlng._notChina) { return false; } // do not check twice same latlng + if (latlng._notChina) { + return false; + } // do not check twice same latlng if (latlng.distanceTo(this._inChinaLastChecked) > this._inChinaValidRadius) { // recheck only when beyond of specified radius, otherwise keep last known value @@ -238,10 +242,12 @@ var fixChinaOffset = { }, _fixChinaOffset: function (latlng) { - if (!this.options.needFixChinaOffset) { return latlng; } - if (!latlng._gcj) { // do not calculate twice same latlng - latlng._gcj = this._isInChina(latlng) && - fixChinaMapOffset.wgs_gcj(latlng); + if (!this.options.needFixChinaOffset) { + return latlng; + } + // do not calculate twice same latlng + if (!latlng._gcj) { + latlng._gcj = this._isInChina(latlng) && fixChinaMapOffset.wgs_gcj(latlng); } return latlng._gcj || latlng; }, @@ -254,11 +260,11 @@ var fixChinaOffset = { _setZoomTransform: function (level, center, zoom) { center = this._fixChinaOffset(center); return L.GridLayer.prototype._setZoomTransform.call(this, level, center, zoom); - } + }, }; // redefine L.GridLayer.GoogleMutant methods -function fixGoogleMutant (_update, style) { +function fixGoogleMutant(_update, style) { return function (wgs) { wgs = wgs || this._map.getCenter(); _update.call(this, wgs); @@ -268,8 +274,7 @@ function fixGoogleMutant (_update, style) { wgs._gcj = wgs._gcj || fixChinaMapOffset.wgs_gcj(wgs); if (o.type === 'hybrid') { var zoom = this._map.getZoom(); - var offset = this._map.project(wgs, zoom) - .subtract(this._map.project(wgs._gcj, zoom)); + var offset = this._map.project(wgs, zoom).subtract(this._map.project(wgs._gcj, zoom)); style.transform = L.Util.template('translate3d({x}px, {y}px, 0px)', offset); } else { this._mutant.setCenter(wgs._gcj); @@ -279,7 +284,7 @@ function fixGoogleMutant (_update, style) { }; } -function setup () { +function setup() { // add support of `needFixChinaOffset` property to any TileLayer L.TileLayer.include(fixChinaOffset); @@ -287,7 +292,7 @@ function setup () { var styleEl = document.createElement('style'); var css = document.body.appendChild(styleEl).sheet; var cssrule = css.cssRules[css.insertRule('.google-mutant .leaflet-tile img:nth-child(2) {}')]; - + // prettier-ignore L.GridLayer.GoogleMutant .mergeOptions({className: 'google-mutant'}) .include(fixChinaOffset) diff --git a/plugins/link-show-direction.js b/plugins/link-show-direction.js index bd7b7f8e4..070ca9475 100644 --- a/plugins/link-show-direction.js +++ b/plugins/link-show-direction.js @@ -4,18 +4,17 @@ // @version 0.2.2 // @description Show the direction of links on the map by adding short dashes to the line at the origin portal. - /* exported setup --eslint */ /* global L, dialog, addHook, map, links */ // use own namespace for plugin var linkShowDirection = {}; window.plugin.linkShowDirection = linkShowDirection; -linkShowDirection.timer = 0; var ANIMATE_UPDATE_TIME = 1000; // 1000ms = 1s // Hack: // 100000 - a large enough number to be the equivalent of 100%, which is not supported Leaflet when displaying with canvas +// prettier-ignore linkShowDirection.styles = { 'Disabled': [null], 'Static *': [ @@ -42,9 +41,10 @@ linkShowDirection.styles = { var dashArray = null; var activeFrame = 0; var moving = false; +var timer = 0; var activeStyle = ''; -function animateLinks () { +function animateLinks() { var frames = linkShowDirection.styles[activeStyle]; if (!frames) frames = [null]; @@ -65,20 +65,20 @@ function animateLinks () { // this would mean the user has no chance to interact with IITC // to prevent this, create a short timer that then sets the timer for the next frame. if the browser is slow to render, // the short timer should fire later, at which point the desired ANIMATE_UPDATE_TIME timer is started - clearTimeout(linkShowDirection.timer); + clearTimeout(timer); linkShowDirection.timer = setTimeout(function () { - clearTimeout(linkShowDirection.timer); - linkShowDirection.timer = setTimeout( - animateLinks, - ANIMATE_UPDATE_TIME); + clearTimeout(timer); + timer = setTimeout(animateLinks, ANIMATE_UPDATE_TIME); }, 10); } -function addAllLinkStyles () { - $.each(links, function(guid,link) { addLinkStyle(link); }); +function addAllLinkStyles() { + $.each(links, function (guid, link) { + addLinkStyle(link); + }); if (window.plugin.drawTools && localStorage['plugin-linkshowdirection-drawtools'] === 'true') { - window.plugin.drawTools.drawnItems.eachLayer(function(layer) { + window.plugin.drawTools.drawnItems.eachLayer(function (layer) { if (layer instanceof L.GeodesicPolyline) { addLinkStyle(layer); } @@ -86,16 +86,18 @@ function addAllLinkStyles () { } } -function addLinkStyle (link) { - link.setStyle({dashArray: dashArray}); +function addLinkStyle(link) { + link.setStyle({ dashArray: dashArray }); } -function removeDrawToolsStyle () { +function removeDrawToolsStyle() { if (!window.plugin.drawTools) return; - window.plugin.drawTools.drawnItems.eachLayer(function(layer) { + window.plugin.drawTools.drawnItems.eachLayer(function (layer) { if (layer instanceof L.GeodesicPolyline) { - layer.setStyle({dashArray: null}); + layer.setStyle({ + dashArray: null, + }); } }); } @@ -103,7 +105,7 @@ function removeDrawToolsStyle () { linkShowDirection.showDialog = function () { var div = document.createElement('div'); - $.each(styles, function(style) { + $.each(linkShowDirection.styles, function (style) { var label = div.appendChild(document.createElement('label')); var input = label.appendChild(document.createElement('input')); input.type = 'radio'; @@ -113,20 +115,27 @@ linkShowDirection.showDialog = function () { input.checked = true; } - input.addEventListener('click', function() { - activeStyle = style; - localStorage['plugin-linkshowdirection-mode'] = style; - animateLinks(); - }, false); + input.addEventListener( + 'click', + function () { + activeStyle = style; + localStorage['plugin-linkshowdirection-mode'] = style; + animateLinks(); + }, + false + ); label.appendChild(document.createTextNode(' ' + style)); div.appendChild(document.createElement('br')); }); - div.appendChild(document.createTextNode( - ' * Static: six segments will indicate each link\'s direction. ' + - 'Two long segments are on the origin\'s side, follow by four short segments on the destination\'s side.')); + div.appendChild( + document.createTextNode( + " * Static: six segments will indicate each link's direction. " + + "Two long segments are on the origin's side, follow by four short segments on the destination's side." + ) + ); if (window.plugin.drawTools) { div.appendChild(document.createElement('br')); @@ -136,15 +145,18 @@ linkShowDirection.showDialog = function () { input.type = 'checkbox'; input.checked = localStorage['plugin-linkshowdirection-drawtools'] === 'true'; - input.addEventListener('click', function() { - localStorage['plugin-linkshowdirection-drawtools'] = input.checked.toString(); - - if (input.checked) { - animateLinks(); - } else { - removeDrawToolsStyle(); - } - }, false); + input.addEventListener( + 'click', + function () { + localStorage['plugin-linkshowdirection-drawtools'] = input.checked.toString(); + if (input.checked) { + animateLinks(); + } else { + removeDrawToolsStyle(); + } + }, + false + ); label.appendChild(document.createTextNode(' Apply to DrawTools')); } @@ -156,10 +168,12 @@ linkShowDirection.showDialog = function () { }); }; -function setup () { +function setup() { $('#toolbox').append('LinkDirection Opt'); - addHook('linkAdded', function(data) { addLinkStyle(data.link); }); + addHook('linkAdded', function (data) { + addLinkStyle(data.link); + }); try { activeStyle = localStorage['plugin-linkshowdirection-mode']; @@ -169,9 +183,12 @@ function setup () { } animateLinks(); - // set up move start/end handlers to pause animations while moving - map.on('movestart', function() { moving = true; }); - map.on('moveend', function() { moving = false; }); + map.on('movestart', function () { + moving = true; + }); + map.on('moveend', function () { + moving = false; + }); } diff --git a/plugins/periodic-refresh.js b/plugins/periodic-refresh.js index e5a05c1bf..eaf3c57c0 100644 --- a/plugins/periodic-refresh.js +++ b/plugins/periodic-refresh.js @@ -12,11 +12,11 @@ window.plugin.periodicRefresh = periodicRefresh; periodicRefresh.refreshMinutes = 60; -function wakeup () { +function wakeup() { console.log('periodicRefresh: timer fired - leaving idle mode'); idleReset(); } -function setup () { - setInterval (wakeup, periodicRefresh.refreshMinutes*60*1000 ); +function setup() { + setInterval(wakeup, periodicRefresh.refreshMinutes*60*1000 ); } From 6c01715431191415edca3cc0734a66f9a51a08d2 Mon Sep 17 00:00:00 2001 From: MysticJay Date: Wed, 9 Aug 2023 09:31:11 +0200 Subject: [PATCH 09/14] line break --- .eslintrc.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 36e3fab88..b4f9dd6e0 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -19,9 +19,5 @@ "eqeqeq": "error", "spaced-comment": "error", "no-unused-expressions": "error", - "linebreak-style": [ - "error", - "windows" - ] } } From 2167da8ff71b1fe93234de21f9dae5e685efc3b6 Mon Sep 17 00:00:00 2001 From: MysticJay Date: Wed, 9 Aug 2023 09:32:37 +0200 Subject: [PATCH 10/14] Update .eslintrc.json --- .eslintrc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index b4f9dd6e0..efa6c4ae0 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,6 +18,6 @@ "rules": { "eqeqeq": "error", "spaced-comment": "error", - "no-unused-expressions": "error", + "no-unused-expressions": "error" } } From db0cc65221c8a303cf0ebbc21d1da800263123b0 Mon Sep 17 00:00:00 2001 From: MysticJay Date: Wed, 9 Aug 2023 09:36:32 +0200 Subject: [PATCH 11/14] Update periodic-refresh.js --- plugins/periodic-refresh.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/periodic-refresh.js b/plugins/periodic-refresh.js index eaf3c57c0..d26d3e215 100644 --- a/plugins/periodic-refresh.js +++ b/plugins/periodic-refresh.js @@ -18,5 +18,5 @@ function wakeup() { } function setup() { - setInterval(wakeup, periodicRefresh.refreshMinutes*60*1000 ); + setInterval(wakeup, periodicRefresh.refreshMinutes * 60 * 1000); } From bb44cca0d9c98eab6e4a92d2efe4fb5ffe180e65 Mon Sep 17 00:00:00 2001 From: MysticJay Date: Wed, 9 Aug 2023 10:20:10 +0200 Subject: [PATCH 12/14] Update scroll-wheel-zoom-disable.js --- plugins/scroll-wheel-zoom-disable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/scroll-wheel-zoom-disable.js b/plugins/scroll-wheel-zoom-disable.js index 63bbae7f1..1c1f5122b 100644 --- a/plugins/scroll-wheel-zoom-disable.js +++ b/plugins/scroll-wheel-zoom-disable.js @@ -6,7 +6,7 @@ /* exported setup --eslint */ -function setup () { +function setup() { window.map.scrollWheelZoom.disable(); } From 67d0279a9501d1cbe882603b034df01f19ab0d36 Mon Sep 17 00:00:00 2001 From: MysticJay Date: Wed, 9 Aug 2023 10:33:36 +0200 Subject: [PATCH 13/14] Update .prettierrc.json remove changes --- .prettierrc.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.prettierrc.json b/.prettierrc.json index a1d1cad80..473a6802b 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -3,6 +3,5 @@ "trailingComma": "es5", "tabWidth": 2, "semi": true, - "singleQuote": true, - "endOfLine":"auto" + "singleQuote": true } From affc01d830a0e53d18efbc001203fccde1495b0a Mon Sep 17 00:00:00 2001 From: MysticJay Date: Fri, 11 Aug 2023 16:35:48 +0200 Subject: [PATCH 14/14] Update link-show-direction.js adressing change Request for showDialog --- plugins/link-show-direction.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/link-show-direction.js b/plugins/link-show-direction.js index 070ca9475..34d16bf07 100644 --- a/plugins/link-show-direction.js +++ b/plugins/link-show-direction.js @@ -102,7 +102,7 @@ function removeDrawToolsStyle() { }); } -linkShowDirection.showDialog = function () { +function showDialog() { var div = document.createElement('div'); $.each(linkShowDirection.styles, function (style) { @@ -169,8 +169,11 @@ linkShowDirection.showDialog = function () { }; function setup() { - $('#toolbox').append('LinkDirection Opt'); - + $('', { + title: 'Change LinkDirection settings', + click: showDialog, + html: 'LinkDirection Opt', + }).appendTo('#toolbox'); addHook('linkAdded', function (data) { addLinkStyle(data.link); });