Add Reddit Post Report Link For Mods

Add a report link on each Reddit post (for Mods). The report link will report the post using "Other" as the reason and without any additional comment. This is roughly the same as the old style of the report link. i.e. without any menus.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Add Reddit Post Report Link For Mods
// @namespace    https://greasyfork.org/en/users/85671-jcunews
// @version      1.0.2
// @license      GNU AGPLv3
// @description  Add a report link on each Reddit post (for Mods). The report link will report the post using "Other" as the reason and without any additional comment. This is roughly the same as the old style of the report link. i.e. without any menus.
// @author       jcunews
// @match        *://www.reddit.com/*
// @grant        none
// ==/UserScript==

//Time delay before reshowing the report link after the previous report attemp has failed (after showing the "report failed" message).
var linkReshowDelay = 3000; //in milliseconds. 1000ms = 1 second.

(function(reportLink) {
  function reportLinkClick(ev, link, tid, xhr) {
    link = this;
    tid = $(link).thing()[0].id.substr(6);
    xhr = new XMLHttpRequest();
    xhr.onload = function(resp, z) {
      try {
        resp = JSON.parse(xhr.responseText);
        if (resp.success) {
          link.nextElementSibling.innerHTML = "reported";
        } else throw 0;
      } catch(z) {
        xhr.onerror();
      }
    };
    xhr.onerror = function() {
      link.nextElementSibling = "report failed";
      setTimeout(function(link) {
        link.style.display = "";
        link.nextElementSibling.innerHTML = "";
      }, linkReshowDelay, link);
    };
    xhr.open("POST", "https://www.reddit.com/api/report", true);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xhr.send("thing_id=" + tid + "&reason=other&other_reason=&id=%23report-action-form&r=" + r.config.post_site + "&uh=" + r.config.modhash + "&renderstyle=html");
    link.style.display = "none";
    link.nextElementSibling.innerHTML = "reporting...";
    ev.preventDefault();
  }
  reportLink = document.createElement("LI");
  reportLink.innerHTML = '<a href="javascript:void(0)">report</a><span></span>';
  document.querySelectorAll(".thing .lock-button").forEach(
    function(ele, linkContainer) {
      linkContainer = reportLink.cloneNode(true);
      linkContainer.firstElementChild.addEventListener("click", reportLinkClick);
      ele = ele.parentNode;
      ele.parentNode.insertBefore(linkContainer, ele.parentNode.querySelector(".crosspost-button").nextElementSibling);
    }
  );
})();