From 9f0997be1a666df19fe25893bd930089a8642c67 Mon Sep 17 00:00:00 2001
From: chylex <contact@chylex.com>
Date: Thu, 21 Sep 2017 08:51:41 +0200
Subject: [PATCH] Refactor some JS

---
 Resources/Plugins/edit-design/browser.js |  4 ++--
 Resources/Scripts/code.js                | 28 +++++-------------------
 Resources/Scripts/notification.js        | 11 +---------
 3 files changed, 8 insertions(+), 35 deletions(-)

diff --git a/Resources/Plugins/edit-design/browser.js b/Resources/Plugins/edit-design/browser.js
index 0ee084a3..b29e8708 100644
--- a/Resources/Plugins/edit-design/browser.js
+++ b/Resources/Plugins/edit-design/browser.js
@@ -108,7 +108,7 @@ enabled(){
       let menu = $(".js-dropdown-content").children("ul").first();
       return if menu.length === 0;
       
-      let itemTD = menu.children("[data-std]").first();
+      let itemTD = menu.children("[data-tweetduck]").first();
       return if itemTD.length === 0;
       
       if (!itemTD.prev().hasClass("drp-h-divider")){
@@ -116,7 +116,7 @@ enabled(){
       }
       
       let itemEditDesign = $('<li class="is-selectable"><a href="#" data-action>Edit layout &amp; design</a></li>');
-      itemTD.after(itemEditDesign);
+      itemEditDesign.insertAfter(itemTD);
       
       itemEditDesign.on("click", "a", this.openEditDesignDialog);
       
diff --git a/Resources/Scripts/code.js b/Resources/Scripts/code.js
index 04c9f9f2..a1324b1e 100644
--- a/Resources/Scripts/code.js
+++ b/Resources/Scripts/code.js
@@ -328,9 +328,8 @@
         let menu = $(".js-dropdown-content").children("ul").first();
         return if menu.length === 0;
         
-        menu.children(".drp-h-divider").last().before('<li class="is-selectable" data-std><a href="#" data-action="tweetduck">TweetDuck</a></li>');
-        
-        let button = menu.children("[data-std]");
+        let button = $('<li class="is-selectable" data-tweetduck><a href="#" data-action>TweetDuck</a></li>');
+        button.insertBefore(menu.children(".drp-h-divider").last());
 
         button.on("click", "a", function(){
           $TD.openContextMenu();
@@ -349,10 +348,6 @@
   // Block: Expand shortened links on hover or display tooltip.
   //
   (function(){
-    var cutStart = function(str, search){
-      return str.startsWith(search) ? str.substr(search.length) : str;
-    };
-    
     var prevMouseX = -1, prevMouseY = -1;
     var tooltipTimer, tooltipDisplayed;
     
@@ -364,13 +359,8 @@
         
         if ($TDX.expandLinksOnHover){
           tooltipTimer = window.setTimeout(function(){
-            let expanded = me.attr("data-full-url");
-            expanded = cutStart(expanded, "https://");
-            expanded = cutStart(expanded, "http://");
-            expanded = cutStart(expanded, "www.");
-
             me.attr("td-prev-text", text);
-            me.text(expanded);
+            me.text(me.attr("data-full-url").replace(/^https?:\/\/(www\.)?/, ""));
           }, 200);
         }
         else{
@@ -1128,18 +1118,10 @@
     return false if $("section.js-column").is(".is-shifted-1,.is-shifted-2");
     
     // all textareas are empty
-    if ($("textarea").is(function(){
-      return $(this).val().length > 0;
-    })){
-      return false;
-    }
+    return false if Array.prototype.some.call(document.getElementsByTagName("textarea"), ele => ele.value.length > 0);
     
     // all columns are scrolled to top
-    if ($(".js-column-scroller").is(function(){
-      return $(this).scrollTop() > 0;
-    })){
-      return false;
-    }
+    return false if Array.prototype.some.call(document.getElementsByClassName("js-column-scroller"), ele => ele.scrollTop > 0);
     
     // cleanup
     window.TDGF_reload();
diff --git a/Resources/Scripts/notification.js b/Resources/Scripts/notification.js
index 29345db1..51e48d52 100644
--- a/Resources/Scripts/notification.js
+++ b/Resources/Scripts/notification.js
@@ -42,10 +42,6 @@
   // Block: Expand shortened links on hover or display tooltip.
   //
   (function(){
-    var cutStart = function(str, search){
-      return str.startsWith(search) ? str.substr(search.length) : str;
-    };
-    
     var prevMouseX = -1, prevMouseY = -1;
     var tooltipTimer, tooltipDisplayed;
     
@@ -60,13 +56,8 @@
 
       if ($TDX.expandLinksOnHover){
         tooltipTimer = window.setTimeout(function(){
-          var expanded = url;
-          expanded = cutStart(expanded, "https://");
-          expanded = cutStart(expanded, "http://");
-          expanded = cutStart(expanded, "www.");
-
           me.setAttribute("td-prev-text", text);
-          me.innerHTML = expanded;
+          me.innerHTML = url.replace(/^https?:\/\/(www\.)?/, "");
         }, 200);
       }
       else{