// ==UserScript== // @name (SE) Markdown on Share links // @version 1.4 // @namespace stackapps.com/users/10590/brasofilo // @description Changes the share links on Q&As to [question-title](http://post-link) // @homepage https://stackapps.com/users/10590/brasofilo // @icon http://i.stack.imgur.com/EX9Al.png // @author brasofilo // @copyright 2014, Rodolfo Buaiz (http://stackapps.com/users/10590/brasofilo) // @license MIT http://opensource.org/licenses/MIT // @match *://*.askubuntu.com/* // @match *://*.mathoverflow.net/* // @match *://*.serverfault.com/* // @match *://*.stackapps.com/* // @match *://*.stackexchange.com/* // @match *://*.stackoverflow.com/* // @match *://*.superuser.com/* // @exclude *://chat.* // @exclude *://blog.* // @exclude *://api.* // @exclude *://data.* // @homepageURL http://stackapps.com/questions/4905/10590 // @updateURL https://gist.github.com/brasofilo/a539c1905608b253fcb6/raw/MarkdownOnShareLinks.user.js // @downloadURL https://gist.github.com/brasofilo/a539c1905608b253fcb6/raw/MarkdownOnShareLinks.user.js // @grant none // ==/UserScript== (function() { 'use strict'; if( StackExchange.options.routeName !== 'Questions/Show' ) return; /** * Escapes brackets on string */ var escapeString =function( str ) { return str.replace(/\[/g, "\\[").replace(/\]/g, "\\]") }; /** * Removes meta content from title and escapes brackets * A title like "Burninate [tag-name] [closed]" will become "Burninate \[always-check-your-errors\]" */ var cleanTitle = function( str ) { let look = [ ' [closed]', ' [duplicate]', ' [on hold]', ' [migrated]', ' [fechado]', ' [duplicado]', ' [suspensa]', ' [migrado]' ]; for (var j=0; j -1 ) { var replace = str.replace(look[j], ''); return escapeString(replace); } } return escapeString(str); }; /** * Restore original share URL */ var restoreURL = function( $goto, $input ) { $input.val( $goto ).select(); }; /** * Replaces the share URL by a markdown link */ var changeShareLink = function( $this ) { let $input = $this.find('.s-popover input:first'); let $url = $input.val(); if ( $this.find('.clean-url').length === 0 ) { let $clean = $( ""); $this.find('div.d-flex').prepend($clean).click(function(e){ e.preventDefault(); restoreURL( $url, $input ); $(this).fadeOut(); }); } let $title = $('#question-header h1 a').text(); $title = cleanTitle($title); console.log($title, $url) let $output = '[' + $title + '](' + $url + ')'; $input.val( $output ).select(); }; $(".js-post-menu a.js-share-link").on("click", function(t) { let $this = $(this).parent(); setTimeout( function(){ changeShareLink( $this ); }, 250 ); }); })();