Twitch Report Underage

Adds a Button which lets you Report Underage (12 Years) Content on Twitch with a single click.

  1. // ==UserScript==
  2. // @name Twitch Report Underage
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Adds a Button which lets you Report Underage (12 Years) Content on Twitch with a single click.
  6. // @author ChoosenEye
  7. // @match https://www.twitch.tv/*
  8. // @grant GM.xmlHttpRequest
  9. // @grant GM.addStyle
  10. // @license GNU General Public License v3.0
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function getCookie(name) {
  17. var nameEQ = name + "=";
  18. var ca = document.cookie.split(';');
  19. for(var i=0;i < ca.length;i++) {
  20. var c = ca[i];
  21. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  22. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  23. }
  24. return null;
  25. }
  26.  
  27.  
  28. GM.addStyle(".reportbutton { line-height: 20px; text-align: center; border-radius: 0.4rem; color: white; width: max-content; background-color: rgb(255, 20, 20); padding: 5px 10px; margin: 0 8px; display:inline-flex; }")
  29. GM.addStyle(".reportbutton:hover { background-color: rgb(200, 20, 20); }");
  30.  
  31. //wait for pageload
  32. window.addEventListener('load', function() {
  33. setTimeout(() => {
  34. AddButton("Underage (12y)");
  35. }, 3500);
  36. }, false);
  37.  
  38. const AddButton = (name) => {
  39. //define Button for Reporting
  40. let image = 'https://cdn.frankerfacez.com/emoticon/427168/1';
  41. let button = document.createElement('div');
  42. button.innerHTML = `<button id="${name}" class="reportbutton"><img style="margin-right: 5px;width:auto;height:20px;" src="${image}" /> ${name} </button>`;
  43. document.querySelector(".metadata-layout__support > div:nth-child(2)").appendChild(button);
  44. document.getElementById(name).addEventListener("click", clickButton);
  45. }
  46.  
  47. const clickButton = () => {
  48. sendGQLReq();
  49. }
  50.  
  51.  
  52. const getChannelId = () => {
  53. let twitchgqlurl = '//gql.twitch.tv/gql'
  54. return new Promise((resolve) => {
  55. GM.xmlHttpRequest({
  56. method: "POST",
  57. headers: {
  58. 'Authorization': `OAuth ${getCookie('auth-token')}`,
  59. 'Client-Id': 'kimne78kx3ncx6brgo4mv6wki5h1ko'
  60. },
  61. url: `https:${twitchgqlurl}`,
  62. data: `{"query": "{user(login: \\"${window.location.pathname.substring(1)}\\", lookupType: ALL) {id}}"}`,
  63. dataType: 'json',
  64. contentType: 'application/json',
  65. overrideMimeType: 'application/json',
  66. onload: (req) => {
  67. console.log(JSON.parse(req.responseText).data.user.id);
  68. resolve(JSON.parse(req.responseText).data.user.id);
  69. }
  70. });
  71. });
  72. }
  73.  
  74.  
  75. const sendGQLReq = async () => {
  76. let ChannelID = await getChannelId();
  77. let twitchgqlurl = '//gql.twitch.tv/gql';
  78.  
  79. GM.xmlHttpRequest({
  80. method: "POST",
  81. headers: {
  82. 'Authorization': `OAuth ${getCookie('auth-token')}`,
  83. 'Client-Id': 'kimne78kx3ncx6brgo4mv6wki5h1ko'
  84. },
  85. url: `https:${twitchgqlurl}`,
  86. data: `{"operationName":"ReportUserModal_ReportUser","variables":{"input":{"description":"report context: USER_REPORT\\n\\nvideo > video more options > underage\\n\\ndescription: child under 12","reason":"underaged","content":"LIVESTREAM_REPORT","contentID":"","extra":"","targetID":"${ChannelID}","wizardPath":["video","video more options","underage"]}},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"dd2b8f6a76ee54aff685c91537fd75814ffdc732a74d3ae4b8f2474deabf26fc"}}}`,
  87. dataType: 'json',
  88. contentType: 'application/json',
  89. overrideMimeType: 'application/json',
  90. onload: (req) => {
  91. let resp = JSON.parse(req.responseText);
  92. if (resp.data.reportContent.contentID === ""){
  93. alert("reported successfully.");
  94. } else {
  95. alert("error occured: " . resp.data.reportContent.contentID);
  96. }
  97. }
  98. });
  99. }
  100.  
  101.  
  102. })();