Last active
September 2, 2018 17:47
-
-
Save Milly/5081829 to your computer and use it in GitHub Desktop.
Add control buttons to tumblr post (Reblog, Edit) Tumblr の個別ポストに「Reblog」「Edit」ボタンを追加します。
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 Tumblr Control | |
// @namespace https://twitter.com/Milly | |
// @description Add control buttons to tumblr post (Reblog, Edit) | |
// @include http://*.tumblr.com/post/* | |
// @grant GM_addStyle | |
// ==/UserScript== | |
GM_addStyle([ | |
'.my-tumblr-control-buttons {', | |
'position: absolute;', | |
'top: 26px;', | |
'right: 2px;', | |
'display: block;', | |
'white-space: nowrap;', | |
'opacity: 0.2;', | |
'transition: opacity .5s linear;', | |
'z-index: 1000;', | |
'}', | |
'.my-tumblr-control-buttons:hover {', | |
'opacity: 1;', | |
'}', | |
'.my-tumblr-control-buttons a {', | |
'margin: 0 2px 0;', | |
'padding: 2px 5px 0;', | |
'height: 18px;', | |
'display: inline-block;', | |
'overflow: hidden;', | |
'border-radius: 3px;', | |
'background: #777;', | |
'color: #fff;', | |
'font-size: 8pt;', | |
'text-decoration: none;', | |
'font-weight: bold;', | |
'text-align: center;', | |
'line-height: 12pt;', | |
'}' | |
].join('')); | |
function createLink(label, type, no_rk) { | |
var redirect = document.location, | |
control = document.getElementById('tumblr_controls').getAttribute('src'), | |
pid = control.match(/(?=[?&]pid=([^&]*)).*/)[1], | |
rk = control.match(/(?=[?&]rk=([^&]*)).*/)[1], | |
base = ['http://www.tumblr.com', type, pid].concat(no_rk ? [] : [rk]), | |
url = base.join('/') + '?redirect_to=' + encodeURIComponent(redirect), | |
eLink = document.createElement('a'); | |
eLink.setAttribute('id', 'my-tumblr-control-' + label.toLowerCase()); | |
eLink.setAttribute('href', url); | |
eLink.appendChild( document.createTextNode(label) ); | |
return eLink; | |
} | |
function addControls() { | |
var elBody = document.getElementsByTagName('body')[0], | |
elLinks = document.createElement('div'); | |
elLinks.setAttribute('id', 'control_links'); | |
elLinks.setAttribute('class', 'my-tumblr-control-buttons'); | |
elLinks.appendChild( createLink('Reblog', 'reblog') ); | |
elLinks.appendChild( createLink('Edit', 'edit', true) ); | |
elBody.appendChild(elLinks); | |
} | |
addControls(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment