From d0ba2970bd3d6c9b16faa7cec10c1ae4ecbd3520 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sun, 11 Aug 2024 23:01:28 +0200 Subject: [PATCH] Removed older browser stuff. --- build.js | 2 +- src/ipaddr.css/main.css | 6 --- src/ipaddr.js/main.js | 115 ++++++++++------------------------------ 3 files changed, 29 insertions(+), 94 deletions(-) diff --git a/build.js b/build.js index b35a2b9..6cc8737 100644 --- a/build.js +++ b/build.js @@ -13,7 +13,7 @@ const exec = require('util').promisify(require('child_process').exec); public: pathJoin(__dirname, 'public'), debug: isDebug, swc: { - es: 'es5', + es: 'es2021', }, vars: { html: {}, // BUG: if this isn't definited prior, assproc will fail diff --git a/src/ipaddr.css/main.css b/src/ipaddr.css/main.css index 87b6c14..32bba7e 100644 --- a/src/ipaddr.css/main.css +++ b/src/ipaddr.css/main.css @@ -26,10 +26,7 @@ body { right: 0; height: 25%; z-index: 0; - background: -moz-linear-gradient(top, #db5176 0%, #ff9290 100%); - background: -webkit-linear-gradient(top, #db5176 0%, #ff9290 100%); background: linear-gradient(to bottom, #db5176 0%, #ff9290 100%); - filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#db5176', endColorstr='#ff9290', GradientType=0); } .background-gradient-bottom { @@ -39,10 +36,7 @@ body { right: 0; height: 25%; z-index: 0; - background: -moz-linear-gradient(top, #ff9290 0%, #4c8999 100%); - background: -webkit-linear-gradient(top, #ff9290 0%, #4c8999 100%); background: linear-gradient(to bottom, #ff9290 0%, #4c8999 100%); - filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff9290', endColorstr='#4c8999', GradientType=0); } .container { diff --git a/src/ipaddr.js/main.js b/src/ipaddr.js/main.js index 806bfff..2ae9fd3 100644 --- a/src/ipaddr.js/main.js +++ b/src/ipaddr.js/main.js @@ -1,100 +1,41 @@ #vars window build -var createXHR = function() { - if('all' in document && !('atob' in window) && 'XDomainRequest' in window) - return new XDomainRequest; - - if('XMLHttpRequest' in window) - return new XMLHttpRequest; - - if('ActiveXObject' in window) - try { - return new ActiveXObject('Msxml2.XMLHTTP'); - } catch(e) { - try { - return new ActiveXObject('Microsoft.XMLHTTP'); - } catch(e) {} - } - - throw 'no impl'; -} - -var getRemoteString = function(url, callback) { - try { - var xhr = createXHR(); - xhr.onload = function(ev) { - callback({ success: true, info: ev, text: xhr.responseText }); - }; - xhr.onerror = function(ev) { - callback({ success: false, info: ev }); - }; +const getRemoteString = url => { + return new Promise((resolve, reject) => { + const xhr = new XMLHttpRequest; + xhr.onload = ev => { resolve(xhr.responseText); }; + xhr.onerror = ev => { reject(); }; xhr.open('GET', url); xhr.send(); - } catch(ex) { - callback({ success: false, info: ex }); - } + }); }; -var copyTextInElement = function(target, skipClipboardAPI) { - if(!skipClipboardAPI && 'clipboard' in navigator) { - // for some reason I'm supporting IE8 with this and it gets mad over the catch keyword... - navigator.clipboard.writeText(target.textContent)['catch'](function(ex) { - copyTextInElement(target, true); - }); - return; - } +(async () => { + const fields = document.querySelectorAll('.js-address'); + const urls = { ipv4: window.IPV4_LOOKUP, ipv6: window.IPV6_LOOKUP }; - if('execCommand' in document) { - if('createTextRange' in document.body) { // MSIE - var range = document.body.createTextRange(); - range.moveToElementText(target); - range.select(); - } else if('getSelection' in window) { // Mozilla - var select = window.getSelection(); - var range = document.createRange(); - range.selectNodeContents(target); - select.removeAllRanges(); - select.addRange(range); - } else return; + for(const field of fields) { + const valueField = field.querySelector('.js-address-value'); + if(valueField === null) + return; - document.execCommand('copy'); - return; - } -}; + valueField.textContent = 'loading...'; -(function() { - var fields = document.querySelectorAll('.js-address'); - var urls = { ipv4: window.IPV4_LOOKUP, ipv6: window.IPV6_LOOKUP }; + const subdomain = field.getAttribute('data-subdomain'); + if(typeof subdomain !== 'string' && !(subdomain in urls)) + return; - for(var i = 0; i < fields.length; ++i) - (function(field) { - var valueField = field.querySelector('.js-address-value'); - if(valueField === null) - return; + const copyButton = field.querySelector('.js-address-copy'); - var setValueField = function(text) { - valueField['textContent' in valueField ? 'textContent' : 'innerText'] = text; + try { + const ipAddr = await getRemoteString(urls[subdomain]); + valueField.textContent = ipAddr; + + copyButton.onclick = async () => { + await navigator.clipboard.writeText(ipAddr); }; - - setValueField('loading...'); - - var subdomain = field.getAttribute('data-subdomain'); - if(typeof subdomain !== 'string' && !(subdomain in urls)) - return; - - var copyButton = field.querySelector('.js-address-copy'); - - getRemoteString(urls[subdomain], function(info) { - - if(!info.success) { - setValueField('not available'); - return; - } - - setValueField(info.text); - - if(copyButton) - copyButton.onclick = function() { copyTextInElement(valueField); }; - }); - })(fields[i]); + } catch(ex) { + valueField.textContent = 'not available'; + } + } })();