// ==UserScript== // @name Stack Exchange, OpenAI detector // @namespace https://github.com/Glorfindel83/ // @description Adds a button to check the probability that a post was written by a bot // @contributor Glorfindel // @contributor Makyen // @contributor PurpleMagick // @updateURL https://raw.githubusercontent.com/Glorfindel83/SE-Userscripts/master/openai-detector/openai-detector.user.js // @downloadURL https://raw.githubusercontent.com/Glorfindel83/SE-Userscripts/master/openai-detector/openai-detector.user.js // @supportURL https://stackapps.com/questions/9611/openai-detector // @version 0.15 // @match *://*.askubuntu.com/* // @match *://*.mathoverflow.net/* // @match *://*.serverfault.com/* // @match *://*.stackapps.com/* // @match *://*.stackexchange.com/* // @match *://*.stackoverflow.com/* // @match *://*.superuser.com/* // @match *://metasmoke.erwaysoftware.com/* // @include /^https:\/\/[%\w-]*openai-detector[%\w-]*\.hf\.space\// // @exclude *://stackexchange.com/* // @exclude *://api.* // @exclude *://blog.* // @exclude *://chat.* // @exclude *://data.* // @exclude *://stackoverflow.com/jobs* // @exclude *://*/tour // @exclude *://*.stackexchange.com/questions/ask // @exclude *://*.stackoverflow.com/questions/ask // @exclude *://*.superuser.com/questions/ask // @exclude *://*.serverfault.com/questions/ask // @exclude *://*.askubuntu.com/questions/ask // @exclude *://*.stackapps.com/questions/ask // @exclude *://*.mathoverflow.net/questions/ask // @connect hf.space // @require https://cdn.jsdelivr.net/gh/makyen/extension-and-userscript-utilities@3b1b0aeae424bfca448d72d60a3dc998d5c53406/executeInPage.js // @require https://cdn.jsdelivr.net/gh/makyen/extension-and-userscript-utilities@703bcfed979737808567e8b91240f984392f85a0/loadXHook.js // @grant GM_xmlhttpRequest // @grant GM.xmlHttpRequest // ==/UserScript== /* globals StackExchange, $, jQuery, makyenUtilities */ (function () { "use strict"; /* * For security reasons, Greasemonkey puts userscripts in a context other than the page * context. The GM.xmlHttpRequest() function is only available in that context, not in * the page context. Most of this script relies on jQuery and access to the StackExchange * Object. Both of those are in the page context. So, most of the script, everything in * the inSEorMSPage() function, is placed in the page context. For the page context to get the * detection data, an event, "SEOAID-request-detection-data", is dispatched with the text to * pass to the OpenAI detector on the button which has been clicked. Once the data is * received, the "SEOAID-receive-detection-data" event is dispatched with the data received * from the OpenAI Detector. */ const IFRAME_HOST = 'openai-openai-detector.hf.space'; const IFRAME_ORIGIN = `https://${IFRAME_HOST}`; const IFRAME_PATH = ''; const IFRAME_URL = IFRAME_ORIGIN + IFRAME_PATH; const IFRAME_ORIGIN_REGEX = /^https:\/\/[%\w-]*openai-detector[%\w-]*\.hf\.space(?:\/|$)/; const DETECTOR_ORIGIN = IFRAME_ORIGIN; const DETECTOR_PATH = '/'; const DETECTOR_BASE_URL = DETECTOR_ORIGIN + DETECTOR_PATH; function inSEorMSPage(iframeOrigin, iframeURL, iframeOriginRegex) { const IFRAME_ORIGIN_IN_PAGE = iframeOrigin; const IFRAME_URL_IN_PAGE = iframeURL; const IFRAME_ORIGIN_REGEX_IN_PAGE = iframeOriginRegex; const cache = {}; const SE_API_CONSTANTS = { key: 'b4pJgQpVylPHom5vj811QQ((', posts: { filter: '38FD8bVlOlsmcYi8', // This is an "unsafe" filter. state: 'PublishedAndStagingGround', // Currently only valid on /posts and /questions pagesize: 100, }, urlPrefix: 'https://api.stackexchange.com/2.4', }; const isMS = window.location.hostname === 'metasmoke.erwaysoftware.com'; // unescapeHTMLText was copied by the author from the FIRE userscript. /** * unescapeHTMLText - Unescapes HTML text. * @param {string} htmlIn HTML text to unescape * @returns {string} Unescaped, and unsafe, HTML text */ function unescapeHTMLText(htmlIn) { // It's necessary here to not use a