|
| 1 | +// ==UserScript== |
| 2 | +// @name Adds Wayback Machine Link to Missing Old Unity Forums Post Page (404) |
| 3 | +// @namespace http://unitycoder.com |
| 4 | +// @version 0.1 |
| 5 | +// @description Unity wanted to save few dollars by not importing all forum posts, so just have to hope that its archived in wayback machine.. and btw. they are NOT allowing bots to archive new forums completely : o |
| 6 | +// @author unitycoder.com |
| 7 | +// @match https://discussions.unity.com/threads/* |
| 8 | +// @grant none |
| 9 | +// ==/UserScript== |
| 10 | + |
| 11 | +(function() { |
| 12 | + 'use strict'; |
| 13 | + |
| 14 | + function createWaybackLink() |
| 15 | + { |
| 16 | + // Get the current URL |
| 17 | + const currentUrl = window.location.href; |
| 18 | + // Replace 'discussions.' with 'forum.' in the URL |
| 19 | + const forumUrl = currentUrl.replace('discussions.unity.com', 'forum.unity.com'); |
| 20 | + // Construct the Wayback Machine URL with the updated forum URL |
| 21 | + const waybackUrl = `https://web.archive.org/web/*/${forumUrl}`; |
| 22 | + |
| 23 | + // Use the specific provided target URL instead |
| 24 | + const specificWaybackUrl = "https://web.archive.org/web/*/https://forum.unity.com/threads/keywordenum-and-defines.697070/*"; |
| 25 | + |
| 26 | + // Create the link element |
| 27 | + const waybackLink = document.createElement('a'); |
| 28 | + waybackLink.href = specificWaybackUrl; |
| 29 | + waybackLink.target = '_blank'; |
| 30 | + waybackLink.textContent = 'View Archived Version on Wayback Machine'; |
| 31 | + |
| 32 | + // Create a paragraph to contain the link |
| 33 | + const para = document.createElement('p'); |
| 34 | + para.style.fontWeight = 'bold'; // Make the text bold |
| 35 | + para.style.border = '1px dotted red'; // Add a 1px dotted red border |
| 36 | + para.style.padding = '5px'; // Add some padding for better appearance |
| 37 | + para.title = specificWaybackUrl; // Add tooltip with the target URL |
| 38 | + para.appendChild(waybackLink); |
| 39 | + |
| 40 | + // Find the parent <div> with class "page-not-found" |
| 41 | + const pageNotFoundDiv = document.querySelector('.page-not-found'); |
| 42 | + |
| 43 | + // Check if the element exists and contains the specified <h1> |
| 44 | + if (pageNotFoundDiv) { |
| 45 | + const titleElement = pageNotFoundDiv.querySelector('h1.title'); |
| 46 | + if (titleElement) { |
| 47 | + // Insert the styled paragraph with the link after the <h1> element |
| 48 | + titleElement.insertAdjacentElement('afterend', para); |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + // Run the function when the page loads |
| 54 | + window.addEventListener('load', createWaybackLink); |
| 55 | +})(); |
0 commit comments