Skip to content

Instantly share code, notes, and snippets.

@ishikawam
Last active May 11, 2018 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishikawam/9c37b76a88559a5f32ea36b2b06908b7 to your computer and use it in GitHub Desktop.
Save ishikawam/9c37b76a88559a5f32ea36b2b06908b7 to your computer and use it in GitHub Desktop.
// ==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(/&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<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