├── .gitignore ├── .vscode └── settings.json ├── extension ├── icon128.png ├── manifest.json └── content.js ├── prettier.config.js ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | *.zip 2 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true 3 | } 4 | -------------------------------------------------------------------------------- /extension/icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eramdam/GifsOnTumblr/HEAD/extension/icon128.png -------------------------------------------------------------------------------- /prettier.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "printWidth": 100, 3 | "tabWidth": 2, 4 | "useTabs": false, 5 | "semi": true, 6 | "singleQuote": true, 7 | "trailingComma": "none", 8 | "bracketSpacing": false, 9 | "jsxBracketSameLine": true 10 | } -------------------------------------------------------------------------------- /extension/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GifsOnTumblr", 3 | "version": "1.1.3", 4 | "manifest_version": 3, 5 | "description": "Brings GIFs back to Tumblr blogs/dashboard instead of WEBPs", 6 | "content_scripts": [ 7 | { 8 | "matches": [""], 9 | "js": ["content.js"] 10 | } 11 | ], 12 | "host_permissions": [""] 13 | } 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GifsOnTumblr 2 | 3 | Tumblr started (badly) converting GIFs to WebP on their dashboard, fucking up glitch art and making saving of GIFs even harder. Screw that. 4 | 5 | This extension tweaks the dashboard to serve GIFs instead of WebP. Unfortunately your browser might download both but it's been written very quickly and out of spite. 6 | 7 | - Firefox https://addons.mozilla.org/en-US/firefox/addon/gifsontumblr/ 8 | - Chrome https://chrome.google.com/webstore/detail/gifsontumblr/ojdchdecabcmdgloljejooedjpgaajbe 9 | 10 | # Motivation 11 | 12 | This post sheds some light on why this is an awful change for GIFs creator on Tumblr https://bigbadbro.tumblr.com/post/187246453755/hi-everyone-absolutely-awful-news-for-all 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Damien Erambert 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /extension/content.js: -------------------------------------------------------------------------------- 1 | function switchAttribute(el, attr) { 2 | const currAttr = el.getAttribute(attr) || ''; 3 | if (!currAttr) { 4 | return; 5 | } 6 | 7 | el.setAttribute(attr, currAttr.replace(/\.gifv/g, '.gif')); 8 | } 9 | 10 | function switchLightbox(el) { 11 | const lightboxJSONString = el.getAttribute('data-lightbox'); 12 | 13 | if (!lightboxJSONString) { 14 | return; 15 | } 16 | 17 | const lightboxJSON = JSON.parse(lightboxJSONString); 18 | 19 | for (const key in lightboxJSON) { 20 | if (lightboxJSON.hasOwnProperty(key)) { 21 | const element = lightboxJSON[key]; 22 | if (String(element).endsWith('.gifv')) { 23 | lightboxJSON[key] = String(element).replace('.gifv', '.gif'); 24 | } 25 | } 26 | } 27 | 28 | el.setAttribute('data-lightbox', JSON.stringify(lightboxJSON)); 29 | } 30 | 31 | const posts = document.body; 32 | 33 | const isTumblrDashboard = 34 | String(window.location).startsWith('https://www.tumblr.com/') || 35 | String(window.location).startsWith('https://tumblr.com/'); 36 | const isTumblrBlog = 37 | Boolean(document.querySelector('iframe.tmblr-iframe')) || 38 | String(window.location).match(/https:\/\/[\w\W]+\.tumblr\.com\/image\//); 39 | 40 | const onMutation = () => { 41 | if (!posts) { 42 | return; 43 | } 44 | 45 | const possibleAttributes = ['href', 'src', 'data-src', 'srcset']; 46 | 47 | possibleAttributes.forEach((attr) => { 48 | Array.from(posts.querySelectorAll(`[${attr}*=".gifv"][${attr}*=".media.tumblr."]`)).forEach( 49 | (el) => { 50 | switchAttribute(el, attr); 51 | } 52 | ); 53 | }); 54 | 55 | // We want to do this only on Tumblr's dashboard 56 | if (isTumblrDashboard) { 57 | const Slideshows = posts.querySelectorAll('[data-lightbox]'); 58 | 59 | Array.from(Slideshows).forEach((el) => switchLightbox(el)); 60 | } 61 | }; 62 | 63 | const postsObserver = new MutationObserver(onMutation); 64 | 65 | console.log({ 66 | isTumblrDashboard, 67 | isTumblrBlog 68 | }); 69 | if (isTumblrDashboard || isTumblrBlog) { 70 | postsObserver.observe(posts, { 71 | childList: true, 72 | subtree: true 73 | }); 74 | 75 | onMutation(); 76 | } 77 | --------------------------------------------------------------------------------