Skip to content

Instantly share code, notes, and snippets.

@pzread
Last active April 21, 2017 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pzread/1e5dd21d832a04b32b60316ded07fbab to your computer and use it in GitHub Desktop.
Save pzread/1e5dd21d832a04b32b60316ded07fbab to your computer and use it in GitHub Desktop.
Mastodon Blocked Contents Loader
// ==UserScript==
// @name Mastodon Blocked Contents Loader
// @namespace http://tampermonkey.net/
// @version 0.1
// @description shows how to use babel compiler
// @author PZ Read
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.16.0/polyfill.js
// @match https://*/*
// ==/UserScript==
// This script only be tested on mastodon.cloud with MS Edge.
/* jshint ignore:start */
var inline_src = (<><![CDATA[
/* jshint ignore:end */
/* jshint esnext: false */
/* jshint esversion: 6 */
var view_href = null;
var observer = new MutationObserver(function(mutations, observer) {
let preview_imgs = document.querySelectorAll('div.scrollable div.status a[style^=\'background: url("/files/small/missing.png")\']');
for (let i = 0; i < preview_imgs.length; i++) {
let e_a = preview_imgs[i];
let href = e_a.href;
e_a.style.background = `url("${href}") no-repeat center / cover`;
e_a.addEventListener('click', () => { view_href = href; });
}
let view = document.querySelector('div.modal-root span[class="imageloader failed"');
if (view !== null && view_href !== null) {
let img = document.createElement('img');
img.src = view_href;
img.style.display = 'block';
view.appendChild(img);
view.className = 'imageloader loaded';
}
});
let observee = [document.querySelector('div.modal-root')];
let timelines = document.querySelectorAll('div.scrollable');
for (let i = 0; i < timelines.length; i++) {
observee.push(timelines[i]);
}
for (let dom of observee) {
observer.observe(dom, {
subtree: true,
attributes: true
});
}
/* jshint ignore:start */
]]></>).toString();
var c = Babel.transform(inline_src, { presets: [ "es2015", "es2016" ] });
eval(c.code);
/* jshint ignore:end */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment