Created
May 14, 2016 15:58
-
-
Save unarist/e172252ac2afa3d7540d2e53ca484a16 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 画面上のツイートをテキストでコピー | |
// @namespace https://github.com/unarist/ | |
// @version 0.1 | |
// @author unarist | |
// @match https://twitter.com/* | |
// @exclude https://twitter.com/i/* | |
// @grant GM_registerMenuCommand | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var chain = f => function() { f.apply(this, arguments); return this; }; | |
var extendTo = (t, o) => { for(var p in o) t[p] = o[p]; }; | |
var here = code => code.toString().match(/\/\*([^]*)\*\//)[1]; | |
var fragment = html => document.createRange().createContextualFragment(html); | |
var $ = document.querySelector.bind(document); | |
var $$ = document.querySelectorAll.bind(document); | |
extendTo(Node.prototype, { | |
on: chain(Node.prototype.addEventListener), | |
appendTo(target) { target.appendChild(this); return this; }, | |
text(t) { this.textContent = t; return this; }, | |
val(v) { this.value = v; return this; } | |
}); | |
extendTo(Element.prototype, { | |
find: Element.prototype.querySelector, | |
findAll: Element.prototype.querySelectorAll, | |
hide() { | |
if(!this.hasOwnProperty('show')) { | |
var prev = this.style.display; | |
this.show = function() { this.style.display = prev; delete this.show; return this; }; | |
this.style.display = 'none'; | |
} | |
return this; | |
} | |
}); | |
for(var prop of ['map', 'filter', 'forEach', 'reduce', 'some', 'every']) | |
NodeList.prototype[prop] = Array.prototype[prop]; | |
var containerHtml = here(function(){/* | |
<div style="position:fixed; top:0; width:100%; height:100%; background: rgba(0,0,0,0.5); z-index: 999"> | |
<textarea style="position:absolute; top:0;left:0;bottom:0;right:0; margin:auto; width:640px; height:480px; background:white;"> | |
</textarea> | |
</div> | |
*/}); | |
var container = fragment(containerHtml).firstElementChild; | |
container.on('click', e => (e.target === e.currentTarget && e.currentTarget.hide())) | |
.hide() | |
.appendTo($('body')); | |
GM_registerMenuCommand('画面上のツイートをテキストでコピー', function() { | |
var tweets = $$('.js-stream-tweet').map((e)=>`@${e.dataset.screenName}: ${e.querySelector('.tweet-text').innerText} (${e.dataset.tweetId})`).reverse().join('\n'); | |
container.find('textarea').val(tweets); | |
container.show(); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment