Last active
April 16, 2018 11:45
-
-
Save unarist/4c207086ece2a370f786a240a7b448d0 to your computer and use it in GitHub Desktop.
:don: - Add web+mastodon://follow link to user page
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 :don: - Add web+mastodon://follow link to user page | |
// @namespace https://github.com/unarist/ | |
// @version 0.3 | |
// @author unarist | |
// @include https://*/@* | |
// @exclude https://*/*/* | |
// @grant none | |
// @downloadURL https://gist.github.com/unarist/4c207086ece2a370f786a240a7b448d0/raw/mastodon-remote-follow-links.user.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const tag = (name, props = {}, children = []) => { | |
const e = Object.assign(document.createElement(name), props); | |
Object.assign(e.style, props.style); | |
(children.forEach ? children : [children]).forEach(c => e.appendChild(c)); | |
return e; | |
}; | |
const toKebabCase = (s) => s.replace(/[A-Z]/g, (c) => '-' + c.toLowerCase()); | |
const styleTag = (rules) => | |
Object.assign(document.createElement('style'), { | |
textContent: Object.entries(rules).map(([selector, styles]) => `${selector}{${Object.entries(styles).map(([k,v]) => toKebabCase(k) + ':' + v).join(';')}}`).join('') | |
}); | |
const host = location.host, | |
username = location.pathname.slice(2); | |
const target = document.querySelector('.p-author .controls'); | |
if (!target) return; | |
const isNewProfile = !target.parentElement.classList.contains('p-author'); | |
document.head.appendChild(styleTag({ | |
'.card .controls': { | |
textAlign: isNewProfile ? 'left' : 'right' | |
}, | |
'._remote-follow-links': { | |
display: 'block', | |
color: window.getComputedStyle(document.querySelector(isNewProfile ? '.card .controls .icon-button' : '.account__header__content')).color, | |
textDecoration: 'none', | |
textShadow: '0 0 8px black', // for light themes (e.g. kktCSS) | |
}, | |
'._remote-follow-links:hover': { | |
textDecoration: 'underline' | |
} | |
})); | |
target.appendChild(tag('a', { | |
href: `https://${host}/users/${username}/remote_follow`, | |
textContent: 'remote follow', | |
className: '_remote-follow-links', | |
style: target.querySelector('.remote-follow') ? { display: 'none' } : {}, | |
// Mastodonしかだめだこれは | |
/*onclick: e => { | |
e.preventDefault(); | |
const follower = prompt('フォロー元のドメインを入力'); | |
if(follower) location.href = `https://${follower}/authorize_follow?acct=${username}%40${host}`; | |
}*/ | |
})); | |
target.appendChild(tag('a', { | |
href: `web+mastodon://follow?uri=${username}@${host}`, | |
textContent: 'web+mastodon://follow', | |
className: '_remote-follow-links', | |
onclick: e => { | |
e.preventDefault(); | |
window.open(e.target.href, '_blank', 'width=400,height=400,resizable=no,menubar=no,status=no,scrollbars=yes'); | |
} | |
})); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment