Browse code

Correction de bugs sur le minifieur d'url + suppression de code mort

Chrisix authored on 12/05/2017 21:08:53
Showing 1 changed files
... ...
@@ -118,35 +118,6 @@ function writePlonk(message, board, post, login, info) {
118 118
     return message;
119 119
 }
120 120
 
121
-function writeUrl(message) {
122
-    var url_exp = new RegExp('(<a.*href="https?:\/\/([^\/?#"]+)(\/[^"?#]+)?["?#].*>)\[url\]');
123
-    function urlMini(m, tag, domain, url, offset, s) {
124
-        if ( /\/.*\.(png|jpg|jpeg|gif|webp)$/i.test(url) ) {
125
-            return tag+"[img]";
126
-        }
127
-        if ( /\/.*\.(mpg|mpeg|mp4|webm|ogv|mkv|avi)$/i.test(url) ) {
128
-            return "[video]";
129
-        }
130
-        if ( /\/.*\.(mp3|ogg|aac|wav|flac)$/i.test(url) ) {
131
-            return "[audio]";
132
-        }
133
-        if ( /\/.*\.pdf$/i.test(url) ) {
134
-            return tag+"[pdf]";
135
-        }
136
-        if ( /\.[^.0-9]+$/.test(domain) ) {
137
-          dispdom = domain.susbtr(0, domain.lastIndexOf('.'));
138
-        }
139
-        else {
140
-          dispdom = domain;
141
-        }
142
-        if (dispdom.substr(0,4) == "www.") {
143
-          dispdom = dispdom.susbtr(4);
144
-        }
145
-        return tag+"["+dispdom+"]";
146
-    }
147
-    return message.replace(url_exp, urlMini);
148
-}
149
-
150 121
 function writeBigorno(message, board, postid, post) {
151 122
     var login_exp = (board.login) ? board.login : settings.value('default_login');
152 123
     if (login_exp) {
... ...
@@ -330,16 +301,16 @@ function urlMini(proto, domain, url) {
330 301
     if ( proto == "f" ) {
331 302
         return "[ftp]";
332 303
     }
333
-    if ( /\/.*\.(png|jpg|jpeg|gif|webp)$/i.test(url) ) {
304
+    if ( /\.(png|jpg|jpeg|gif|webp)$/i.test(url) ) {
334 305
         return "[img]";
335 306
     }
336
-    if ( /\/.*\.(mpg|mpeg|mp4|webm|ogv|mkv|avi)$/i.test(url) ) {
307
+    if ( /\.(mpg|mpeg|mp4|webm|ogv|mkv|avi)$/i.test(url) ) {
337 308
         return "[video]";
338 309
     }
339
-    if ( /\/.*\.(mp3|ogg|aac|wav|flac)$/i.test(url) ) {
310
+    if ( /\.(mp3|ogg|aac|wav|flac)$/i.test(url) ) {
340 311
         return "[audio]";
341 312
     }
342
-    if ( /\/.*\.pdf$/i.test(url) ) {
313
+    if ( /\.pdf$/i.test(url) ) {
343 314
         return "[pdf]";
344 315
     }
345 316
     var dispdom = domain;
... ...
@@ -427,9 +398,11 @@ function insertToPinni(post, postId, board, clock, login, info, message, realId)
427 398
         // Toujours ouvrir les urls dans un autre onglet
428 399
         urls[i].setAttribute('target','_blank');
429 400
         var href = urls[i].getAttribute('href');
430
-        if (href && urls[i].innerHTML.strip() == "[url]") {
401
+        if (href && /\[(url|https?)\]/.test(urls[i].innerHTML.strip()) ) {
431 402
             var m = url_exp.exec(href);
432
-            urls[i].innerHTML = urlMini(m[1], m[2], m[3]);
403
+            if (m) {
404
+              urls[i].innerHTML = urlMini(m[1], m[2], m[3]);
405
+            }
433 406
         }
434 407
     }
435 408
     board.notify(NOTIF_NEW_POST, postId, post);