Last active
December 15, 2016 02:50
-
-
Save unarist/e58f7a051c285d614a89 to your computer and use it in GitHub Desktop.
Transifexで原文と訳文をまとめてコピーするやつ
This file contains 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 Transifexで原文と訳文をまとめてコピーするやつ | |
// @namespace https://github.com/unarist/ | |
// @downloadURL https://gist.githubusercontent.com/unarist/e58f7a051c285d614a89/raw/transifex-copyall.user.js | |
// @version 0.6 | |
// @description enter something useful | |
// @author unarist | |
// @match https://www.transifex.com/*/translate/ | |
// @require https://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js | |
// @grant none | |
// ==/UserScript== | |
function here(code) { | |
return code.toString().match(/\/\*([^]*)\*\//)[1]; | |
} | |
var template = here(function(){/* | |
---- | |
transifex:{{id}}:{{&url}} | |
> {{&source}} | |
> {{&translated}} | |
---- | |
*/}).trim(); | |
var containerHtml = here(function(){/* | |
<div style="position:fixed; top:0; width:100%; height:100%; background: rgba(0,0,0,0.5); display:none; z-index: 999"> | |
<textarea style="position:absolute; top:0;left:0;bottom:0;right:0; margin:auto; width:520px; height:240px; background:white;"> | |
</textarea> | |
</div> | |
*/}); | |
var container = $(containerHtml).appendTo('body').click(function(e){ if(e.target === this) $(this).hide(); }); | |
function showSnippet() { | |
var model = { | |
id: /\/(\d+)\??/.exec(location.hash)[1], | |
url: location.href.split("?")[0] + '?key=' + $('.u-color-secondary.u-fontWeight-thin:first').text().trim(), | |
source: $("#source-string").text(), | |
translated: $("#translated-string").val() | |
}; | |
container.show().children().val(Mustache.render(template, model)).select(); | |
} | |
$('<li><a class="js-translation-tool o-button o-button--fill o-button--autowidth">まとめてコピー</a></li>') | |
.children().click(showSnippet).end() | |
.prependTo('#operation-area .transactions'); |
@ento ありがとうございます、早速やってみました。便利だ・・・。
Rawボタンのリンク先はリビジョン指定を含んでいるので更新チェックがうまく働かなくて困っていたのですが、その部分を除いたURLを @downloadURL
に指定しておくと大丈夫みたいですね。(c.f. greasemonkey/greasemonkey#1656 (comment))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
.user.jsで終わるファイル名にしておくと、RawボタンをクリックするだけでTampermonkeyのスクリプトインストール画面に飛べるようです。