Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
// ==UserScript== // @name SpongeForum Video Fix // @namespace SpongeForum // @version 1.0 // @description Fix for the broken video embeds on SpongeForum.de // @author Reschif der fette // @grant none // ==/UserScript== (function() { 'use strict'; if (window.location.hostname === 'spongeforum.de') { document.querySelectorAll('iframe.videoBBCodeObject.youtube-player').forEach((iframe) => { const youtubeId = iframe.src.match(/youtube\.com\/embed\/([a-zA-Z0-9_-]+)/)[1]; const newEmbed = document.createElement('iframe'); newEmbed.src = `https://www.youtube.com/embed/${youtubeId}`; newEmbed.width = "400"; newEmbed.height = "315"; newEmbed.classList.add('videoBBCodeObject', 'youtube-player'); iframe.parentNode.replaceChild(newEmbed, iframe); }); } })(); |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
{ "manifest_version": 3, "name": "SpongeForum Video Fix", "version": "1.0", "permissions": ["activeTab", "tabs"], "host_permissions": ["*://*/*"], "background": { "service_worker": "background.js" }, "content_scripts": [ { "matches": ["*://spongeforum.de/*"], "js": ["content.js"] } ] } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 |
chrome.runtime.onInstalled.addListener(function() { chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { if (tab.url && tab.url.includes('spongeforum.de')) { chrome.action.enable(tabId); } else { chrome.action.disable(tabId); } }); }); |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
window.onload = function() { var videoPlayers = Array.from(document.getElementsByClassName('videoBBCodeObject youtube-player')); for (var i = 0; i < videoPlayers.length; i++) { var videoURL = videoPlayers[i].src; var youtubeIndex = videoURL.indexOf('youtube.com/embed/'); if (youtubeIndex !== -1) { var videoId = videoURL.slice(youtubeIndex + 18, youtubeIndex + 29); var newVideoEmbed = document.createElement('iframe'); newVideoEmbed.setAttribute('src', 'https://www.youtube.com/embed/' + videoId); newVideoEmbed.setAttribute('frameborder', '0'); newVideoEmbed.setAttribute('allow', 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture'); newVideoEmbed.setAttribute('allowfullscreen', ''); // Set the size of the player newVideoEmbed.style.width = '400px'; newVideoEmbed.style.height = '315px'; // Replace the old iframe with the new one var parent = videoPlayers[i].parentNode; parent.replaceChild(newVideoEmbed, videoPlayers[i]); } } }; |
Benutzerinformationen überspringen
Voll auf Muskatnuss
Dabei seit: 27. Juli 2013
Beruf: Prof. Dr. Schläck, studierte in Oxford Sozialwissenschaften
Benutzerinformationen überspringen
Voll auf Muskatnuss
Dabei seit: 27. Juli 2013
Beruf: Prof. Dr. Schläck, studierte in Oxford Sozialwissenschaften
hab einfach mal chatgpt gebeten das image-script so zu erweitern dass große bilder automatisch auf eine bestimmte breite verkleinert werden. Ist bestimmt nicht optimal gecoded, aber whatever, ich kenn mich mit der materie nicht aus und es funktioniert zumindestens http://bikinibottom.de/s/i8qrW.gif
Spoiler
Quellcode
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 // ==UserScript== // @name Spongeforum-Image-Inliner // @namespace spongeforum // @description Display linked images inline and resize them to a width of 850 pixels if their width is larger // @include http://spongeforum.de* // ==/UserScript== var processedImages = false; function addListener(obj, eventName, listener) { if (obj.addEventListener) { obj.addEventListener(eventName, listener, false); } else { obj.attachEvent("on" + eventName, listener); } } function resizeImageIfNeeded(img) { var maxWidth = 850; var currentWidth = img.width; if (currentWidth > maxWidth) { img.style.maxWidth = maxWidth + "px"; img.style.width = "100%"; } } function LocalMain() { if (processedImages) { return; } processedImages = true; var imageLinks = document.evaluate( "//a[@class='image']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null ); var imageCount = imageLinks.snapshotLength; for (var i = 0; i < imageCount; i++) { var item = imageLinks.snapshotItem(i); var url = item.getAttribute('href'); var img = document.createElement('img'); img.setAttribute('src', url); img.setAttribute('class', 'resizeImage'); // Resize the image if its width is larger than 850 pixels img.onload = function() { resizeImageIfNeeded(this); }; item.parentNode.replaceChild(img, item); } } addListener(document, "DOMContentLoaded", LocalMain); addListener(window, "load", LocalMain);
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
// ==UserScript== // @name Spongeforum-Image-Inliner // @namespace spongeforum // @description Display linked images inline and resize them to a width of 850 pixels if their width is larger // @include http://spongeforum.de* // ==/UserScript== var processedImages = false; function addListener(obj, eventName, listener) { if (obj.addEventListener) { obj.addEventListener(eventName, listener, false); } else { obj.attachEvent("on" + eventName, listener); } } function resizeImageIfNeeded(img) { var maxWidth; if (img.parentNode.classList.contains('quoteBody')) { maxWidth = 200; }else{ maxWidth = 850; } var currentWidth = img.width; if (currentWidth > maxWidth) { img.style.maxWidth = maxWidth + "px"; img.style.width = "100%"; } } function LocalMain() { if (processedImages) { return; } processedImages = true; var imageLinks = document.evaluate( "//a[@class='image']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null ); var imageCount = imageLinks.snapshotLength; for (var i = 0; i < imageCount; i++) { var item = imageLinks.snapshotItem(i); var url = item.getAttribute('href'); var img = document.createElement('img'); img.setAttribute('src', url); img.setAttribute('class', 'resizeImage'); // Resize the image if its width is larger than 850 pixels img.onload = function() { resizeImageIfNeeded(this); }; item.parentNode.replaceChild(img, item); } } addListener(document, "DOMContentLoaded", LocalMain); addListener(window, "load", LocalMain); |