KawaiZombi / Reactor copyleft

// ==UserScript==
// @name        Reactor copyleft
// @namespace   joyreactor.cc
// @description Restore "Copyrighted" posts
// @match       *://*.reactor.cc/*
// @match       *://joyreactor.cc/*
// @grant       GM_xmlhttpRequest
// @version     1.0
// @author      kawaizombi
// @license     MIT
// ==/UserScript==


(async () => {
  function request(url) {
    return new Promise((resolve, reject) => GM_xmlhttpRequest({
      url,
      responseType: 'document',
      onload: ({ response }) => resolve(response),
      onerror: reject,
    }));
  }

  const COPYWRITE_SELECTOR = '[alt=Copywrite]';
  const POST_CONTAINER_SELECTOR = '[id^=postContainer]';
  const POST_CONTENT_SELECTOR = '.post_content';
  const MOBILE_REACTOR_URL = 'http://m.reactor.cc';
  const POST_ID_REGEXP = /\d+$/;

  for(const el of document.querySelectorAll(COPYWRITE_SELECTOR)) {
    const container = el.closest(POST_CONTAINER_SELECTOR);
    const id = container.getAttribute('id').match(POST_ID_REGEXP)[0];
    const url = `${MOBILE_REACTOR_URL}/post/${id}`;
    const doc = await request(url);
    const content = doc.querySelector(POST_CONTENT_SELECTOR);

    container.querySelector(COPYWRITE_SELECTOR).replaceWith(content);
  }
})();