Factorio Free Mods Downloader from re146.dev

Changes all the links for download on https://mods.factorio.com with force download links. Dont Forget say Thanks to re146.dev

目前为 2024-11-17 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Factorio Free Mods Downloader from re146.dev
  3. // @namespace https://re146.dev/
  4. // @version 1.5
  5. // @description Changes all the links for download on https://mods.factorio.com with force download links. Dont Forget say Thanks to re146.dev
  6. // @author Devito
  7. // @match https://mods.factorio.com/mod/*
  8. // @match https://mods.factorio.com/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=mods.factorio.com
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13.  
  14.  
  15. function FactorioFreeModsDownloader() {
  16. 'use strict';
  17. //Инициализируем переменную с названием мода
  18. var ModNameGlobal = 0;
  19. // Проверяем, подходит ли ссылка под условие
  20. if (/^https:\/\/mods\.factorio\.com\/mod\/([^\/]+)/.test(location.href)) {
  21. // Если подходит, извлекаем имя мода
  22. ModNameGlobal = location.href.match(/^https:\/\/mods\.factorio\.com\/mod\/([^\/]+)/)[1];
  23. // Убираем все, что идет после символа вопросительного знака (если он есть)
  24. ModNameGlobal = ModNameGlobal.split('?')[0];
  25. }
  26. /*
  27. const elems = document.querySelectorAll(".button-green");
  28. [].forEach.call(elems, function(el) {
  29. el.classList.remove("disabled");
  30. });
  31. */
  32. let buttons = Array.from(document.getElementsByClassName('button-green'));
  33. for (const button of buttons) {
  34. let modName = ModNameGlobal
  35. const buttonText = button.innerText.trim().toLowerCase();
  36. const buttonParentType = button.parentElement.tagName.toLowerCase()
  37. // Если текст кнопки 'download'
  38. if (buttonText === 'download') {
  39. button.classList.remove('disabled');
  40. // Если модуль еще не задан, извлекаем название мода
  41. if (!modName) {
  42. const tempname = button.closest('.panel-inset-lighter')
  43. .querySelector('.result-field')
  44. .getAttribute('href');
  45. modName = tempname.split('?')[0].split('/mod/')[1];
  46. }
  47. // Определяем базовую логику для обновления кнопки
  48. const updateButton = (href) => {
  49. button.innerText = 'DownLoad';
  50. button.setAttribute('target', '_blank');
  51. button.setAttribute('href', href);
  52. };
  53. // Устанавливаем ссылки и другие атрибуты в зависимости от родительского элемента
  54. if (buttonParentType === 'div') {
  55. const href = `https://re146.dev/factorio/mods/ru#https://mods.factorio.com/mod/${modName}`;
  56. updateButton(href);
  57. } else if (buttonParentType === 'td') {
  58. const version = button.parentElement.parentElement.children[0].innerText;
  59. const href = `https://mods-storage.re146.dev/${modName}/${version}.zip`;
  60. updateButton(href);
  61. }
  62. }
  63. }
  64. }
  65.  
  66.  
  67. FactorioFreeModsDownloader();
  68.  
  69. // Выбираем элемент для наблюдения
  70. const indicator = document.getElementById('indicator');
  71. const observer = new MutationObserver((mutationsList, observer) => {
  72. // Здесь вы можете проверять, что именно изменилось на странице
  73. mutationsList.forEach(mutation => {
  74. if (mutation.type === 'attributes') {
  75. // Если структура DOM изменилась (например, добавление новых элементов)
  76. FactorioFreeModsDownloader();
  77. }
  78. });
  79. });
  80. // Определяем параметры для наблюдения
  81. const config = {
  82. attributes: true, // Отслеживание изменений атрибутов (опционально)
  83. };
  84. // Начинаем наблюдение за indicator или любым другим элементом, который вам нужен
  85. observer.observe(indicator, config);