Last active
May 11, 2018 08:58
-
-
Save ishikawam/9c37b76a88559a5f32ea36b2b06908b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Replace 4 spaces with a tab character for Slack. | |
// @namespace M_Ishikawa | |
// @version 0.1 | |
// @description Slack 4スペースをタブ文字に変換 | |
// @author Masayuki Ishikawa | |
// @match https://*.slack.com/* | |
// @grant none | |
// ==/UserScript== | |
/** | |
* https://qiita.com/M_Ishikawa/items/8d8db8d0c50039777f00 | |
* Slackはタブ文字を投稿するとスペース4字に変換してしまう。コピペで困る。 | |
* ので、要素をclickするとスペース4字をタブ文字に変換する。 | |
* <pre>のみで有効。 | |
*/ | |
(function() { | |
'use strict'; | |
$(window).on('click', function(e) { | |
if ($(e.target).prop("tagName") !== 'PRE' || $(e.target).attr('data-tab')) { | |
return; | |
} | |
$(e.target).attr('data-tab', true); | |
var str = $(e.target).html(); | |
var newStr = $(e.target).html().replace(/ <wbr> <wbr> <wbr> <wbr>/g, '\t'); | |
if (newStr != str) { | |
$(e.target).html(newStr); | |
// delete '```' | |
$(e.target).removeAttr('data-stringify-prefix'); | |
$(e.target).removeAttr('data-stringify-suffix'); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment