Skip to content

Instantly share code, notes, and snippets.

@DenVdmj
Last active Jun 30, 2018
Embed
What would you like to do?
Добавляет на каждую страницу Хабра кнопку перехода на http://sohabr.so и http://itnan.ru
{
"manifest_version": 2,
"name": "sohabr.net button",
"description": "sohabr.net button for habr.com",
"version": "0.0.1.0",
"icons": {
"64": "sohabr.png"
},
"applications": {
"gecko": {
"id": "noneid@mozilla.org",
"strict_min_version": "45.0"
}
},
"content_scripts": [{
"js": ["sohabr-button.js"],
"matches": [
"*://habr.com/*",
"*://geektimes.com/*"
],
"run_at": "document_start",
"all_frames": true
}],
"permissions": [
"*://habr.com/*",
"*://geektimes.com/*"
]
}
{
"manifest_version": 2,
"name": "sohabr.net button",
"description": "sohabr.net button for habr.com",
"version": "0.0.1.0",
"icons": {
"64": "sohabr.png"
},
"content_scripts": [{
"js": ["sohabr-button.js"],
"matches": [
"*://habr.com/*",
"*://geektimes.com/*"
],
"run_at": "document_start",
"all_frames": true
}],
"permissions": [
"*://habr.com/*",
"*://geektimes.com/*"
]
}
//
// Добавляет на каждую страницу Хабра кнопку перехода на http://sohabr.so и http://itnan.ru
//
const ready = callback =>
!window.TMpanel &&
setTimeout(ready.bind(null, callback))
|| callback()
;
const createLink = (url, name) =>
(a =>
((a.href = url), (a.textContent = name), a)
)(document.createElement('a'))
;
const pubid = (document.location.pathname.match(/\/(\d+)\/?$/) || [])[1];
if (pubid) {
ready(() => {
const menu = document.querySelector('#TMpanel > .container > .bmenu');
if (menu) {
const sohabr = createLink(document.location, 'СоХабр');
sohabr.hostname = 'sohabr.net';
menu.append(sohabr);
menu.append(createLink(`https://itnan.ru/post.php?c=1&p=${pubid}`, 'ITnan'));
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment