Linkformat

replace links in next line with links in () with only domain as text

2016-01-02 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Linkformat
// @namespace    https://bytespeicher.org/
// @version      0.6
// @description  replace links in next line with links in () with only domain as text
// @author       mkzero + chaos
// @match        https://bytespeicher.org/wp-admin/post.php?post=*&action=edit
// @match        https://bytespeicher.org/wp-admin/post-new.php
// @match        https://bytespeicher.org/wp-admin/post.php?post=1261&action=edit
// @grant        none
// ==/UserScript==
/* jshint -W097 */
'use strict';



var menu = document.getElementById('ed_toolbar'),
    newinput = document.createElement("input");

newinput.type = "button";
newinput.id = "qt_content_format_links";
newinput.className = "ed_button button button-small";
newinput.value = "Fix Links";
newinput.addEventListener('click',replace_text,true);
menu.appendChild(newinput);

function replace_text(){
    var i = 0, j = 0,
    lines = document.getElementById('content').innerHTML.split('\n'),
    newdoc = [],
    match = /(?:(http|ftp)(s|):\/\/)([a-z-.]+[a-z]+)/,
    link = /(href="|>)((http|ftp)(s|):\/\/)([a-z-.]+[a-z]+)/,
    excludeHosts = ['twitter.com'],
    fullLinkHosts = ['technikkultur-erfurt.de', 'bytespeicher.org'],
    hostname;
    for (i = 0; i <= lines.length; i+=1) {
        if (match.test(lines[i]) && !link.test(lines[i]) && !(new RegExp(excludeHosts.join("|")).test(lines[i]))) {
            if (!(new RegExp(fullLinkHosts.join('|')).test(lines[i]))) {
                hostname = match.exec(lines[i]);
                hostname = hostname[hostname.length - 1];
                newdoc[j-1] = lines[i-1].trimRight() + ' (<a href=' + lines[i] + '>' + hostname + '</a>)';
            } else {
                newdoc[j-1] = '<a href=' + lines[i] + '>' + lines[i-1] + '</a>';
                if (newdoc[j-1].indexOf('>* ')) {
                    newdoc[j-1] = '* ' + newdoc[j-1].replace('* ', '');
                }
            }
        } else {
            newdoc[j] = lines[i];
            j += 1;
        }
    }
    document.getElementById('content').innerHTML = newdoc.join('\n');   
}