Skip to content

Instantly share code, notes, and snippets.

@unarist
Last active December 15, 2016 02:50
Show Gist options
  • Save unarist/e58f7a051c285d614a89 to your computer and use it in GitHub Desktop.
Save unarist/e58f7a051c285d614a89 to your computer and use it in GitHub Desktop.
Transifexで原文と訳文をまとめてコピーするやつ
// ==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
Copy link

ento commented Apr 7, 2015

.user.jsで終わるファイル名にしておくと、RawボタンをクリックするだけでTampermonkeyのスクリプトインストール画面に飛べるようです。

@unarist
Copy link
Author

unarist commented Apr 8, 2015

@ento ありがとうございます、早速やってみました。便利だ・・・。

@unarist
Copy link
Author

unarist commented Jun 17, 2016

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