medium bypass

bypass medium paywall by using archive.is

  1. // ==UserScript==
  2. // @name medium bypass
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-08-19
  5. // @description bypass medium paywall by using archive.is
  6. // @author The DT
  7. // @match https://*/*
  8. // @icon https://github.com/thedtvn/thedtvn/raw/main/trace.svg?raw=true
  9. // @grant none
  10. // @license Apache License 2.0
  11. // ==/UserScript==
  12.  
  13. (async function() {
  14. 'use strict';
  15.  
  16. // archive.is Part
  17. if (location.href.match(/^https?:\/\/archive\.is\/[a-zA-Z0-9]{5}/)) {
  18. let container = document.body;
  19. let clone_div = document.getElementById("CONTENT");
  20. let clone_input_header = document.querySelector('[name="q"]');
  21. console.log(clone_input_header);
  22. for (let i of document.querySelectorAll("a")) {
  23. if (i.href.startsWith("https://archive.is/o/")) {
  24. i.href = i.href.replace(/^https?:\/\/archive\.is\/o\/[a-zA-Z0-9]{5}\//, "");
  25. }
  26. i.removeAttribute("target");
  27. }
  28. container.innerHTML = "";
  29. clone_div.style = "";
  30. clone_input_header.style = "text-align: center;"
  31. clone_input_header.style.width = "100%";
  32. container.style = "overflow-x: hidden; margin: 0px;"
  33. container.insertBefore(clone_div, container.firstChild);
  34. container.insertBefore(clone_input_header, container.firstChild);
  35. document.getElementById("hashtags").remove()
  36. let dialog_box = document.querySelector('[role="dialog"]');
  37. if (!dialog_box) return
  38. dialog_box.remove()
  39. return
  40. }
  41.  
  42. // Medium Part
  43. function check_is_pre() {
  44. let elm = document.querySelector('[type="application/ld+json"]');
  45. if (!elm) return false
  46. let json_data_str = elm.innerText;
  47. let json_data = JSON.parse(json_data_str);
  48. return json_data.isAccessibleForFree == "False";
  49. }
  50. function check() {
  51. let is_pre = check_is_pre();
  52. if (!is_pre) return
  53. let pageurl = location.href;
  54. let url_obj = new URL("https://archive.is/submit/");
  55. url_obj.searchParams.set("submitid", "");
  56. url_obj.searchParams.set("url", pageurl);
  57. location.replace(url_obj.href);
  58. }
  59. let is_site_meta = document.querySelector('meta[property="og:site_name"]');
  60. if (!is_site_meta) return
  61. let is_medium = is_site_meta.content == "Medium";
  62. if (!is_medium) return
  63. check()
  64. window.addEventListener("pushState", async (event) => {
  65. await new Promise(r => setTimeout(r, 1000));
  66. check()
  67. });
  68. })();