UserScript - Report

05/13/2020 19:02 Devsome#1
Hallo Elitepvpers-Community,

Ich release hier meine UserScripte um Beiträge schnell zu reporten & Signature zu Scannen ob diese größer als Erlaubt sind.


Update: der Mention Troll in der Section hat wieder zugeschlagen, schaut am besten im Archiv.zip nach. + der Anhang wurde bearbeitet und auf 700KB erweitert.

Das Hauptscript:

Code:
// ==UserScript==
//   [MENTION=286917]name[/MENTION]          Report SRO Advertisting Spam
//   [MENTION=1005418]namespace[/MENTION]     [url]http://tampermonkey.net/[/url]
//   [MENTION=1805674]Version[/MENTION]       0.2
//  [MENTION=3833773]Description[/MENTION]   Marking all Post with given bad words and can report easy
// [MENTION=1332190]author[/MENTION]        Devsome
//  [MENTION=340885]match[/MENTION]         [url]https://www.tampermonkey.net/index.php?version=4.9&ext=dhdg&updated=true[/url]
//  [MENTION=551144]grant[/MENTION]         none
//   [MENTION=1474840]reQuire[/MENTION]       [url]http://code.jquery.com/jquery-3.4.1.min.js[/url]
//  [MENTION=1392090]include[/MENTION]       [url]https://www.elitepvpers.com/forum/*[/url]
//  [MENTION=1392090]include[/MENTION]       [url]http://www.elitepvpers.com/forum/*[/url]
// ==/UserScript==

(function() {
    'use strict';
    // start of script


    jQuery.expr[':'].icontains = function(a, i, m) {
      return jQuery(a).text().toUpperCase()
          .indexOf(m[3].toUpperCase()) >= 0;
    };

    let wordArray = [
      'good', 'luck', 'gl'
    ];

    var color = '#870A30';
    var rgbaCol = 'rgba(' + parseInt(color.slice(-6,-4),16)
        + ',' + parseInt(color.slice(-4,-2),16)
        + ',' + parseInt(color.slice(-2),16)
        +',0.5)';

    $(wordArray).each(function () {
      $("[id^=post_message]:icontains(" + this + ")").css('background-color', rgbaCol);
    });


    $('img[title="Beitrag melden"]').each(function( index ) {
        let url = $( this ).parent().attr('href');
        let postId = url.split('=').pop();
        let reportedCounter = window.localStorage.getItem('counter');

        if ( window.localStorage.getItem(postId) ===  postId) {
            $( this ).parent().after( '<div class="reportOwn" data-url=false>Already Reported!</div>' );
        } else {
            $( this ).parent().after(
              '<select class="selectText">'+
                '<option value="Refrain from commenting in threads with quotes such as Good luck or Good server they will be considered as spam.">GL</option>'+
                '<option value="Post hunting with Welcome or :(´´ to every User is spam.">Hunting</option>'+
                '<option value="This Signatur is larger then 700 KB">Signatur</option>'+
              '</select>' +
              '<div class="reportOwn" data-id="'+index+'" data-url="'+url+'" data-text="">Report! ('+reportedCounter+')</div>'
            );
        }
    });

    let script = document.createElement("script");
    script.src = "https://www.elitepvpers.com/forum/mwmods/bump/js/bump.min.js?v=1.1.2";
    document.getElementsByTagName("head")[0].appendChild(script);

    let css = document.createElement("link");
    css.rel = "stylesheet";
    css.type = "text/css";
    css.href = "https://www.elitepvpers.com/forum/mwmods/bump/css/bump.min.css?v=1.1.2";
    document.getElementsByTagName("head")[0].appendChild(css);

    $( ".selectText" ).change(function() {
      $(this).next('.reportOwn').data('text', $(this).val());
    });

    $('.reportOwn').click(function() {
        event.preventDefault();
        let dataUrl = $(this).data('url');
        if(dataUrl === false) {
            return;
        }
        let securitytoken = SECURITYTOKEN;
        let postId = dataUrl.split('=').pop();
        let textDiv = $(this);

        let reportText = $(this).data('text');
        if(!reportText.trim()) {
          reportText = 'This is marked as Spam. My script is not working fine, please contact me';
        }
        $(this).text('Pending');
        $.ajax({
            url: dataUrl,
            type: 'POST',
            data: {
              // Refrain from commenting in threads with quotes such as "Good luck" or "Good server" they will be considered as spam.
              // Post hunting with "Welcome" or ":)" to every User is spam.
                'reason': reportText,
                'do': 'sendemail',
                'url': 'showthread.php?p=' + postId + '#post' + postId,
                'securitytoken': securitytoken
            },
            datatype: 'json',
            success: function (data) {
                successFunction(textDiv, postId);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                console.log('error', textStatus, errorThrown, jqXHR);
                if(textStatus === 'error') {
                  errorFunction(textDiv, postId, jqXHR.responseText);
                    textDiv.text('Retry!');
                }
            }
        });
    });

    function errorFunction(textDiv, postId, text) {
      let regex = /\d+/gm;
      let matchTimer = 0;
      let match;
      while (match = regex.exec(text)) {
        matchTimer = match[0];
      }
      $("body").qtip({
          content: {
              text: 'Du musst noch ' + matchTimer + ' Sekunden warten!',
              title: 'Fehler',
          },
          position: {
              my: "top",
              at: "top",
              target: $(window)
          },
          show: {
              ready: true,
          },
          hide: {
              fixed: true,
              delay: 500
          },
          style: 'qtip qtip-default qtip-red qtip-shadow qtip-rounded qtip-pos-tl',
      });
    }

    function successFunction(textDiv, postId) {
        let n = window.localStorage.getItem('counter');
        if (n === null) {
            n = 0;
        } else {
            n++;
        }

        window.localStorage.setItem(postId, postId);
        window.localStorage.setItem("counter", n);

        textDiv.text('Successfully (' + n + ')');

        $("body").qtip({
            content: {
                text: 'Dies ist nun dein ' + n + ' report!',
                title: 'Erfolgreich',
            },
            position: {
                my: "top",
                at: "top",
                target: $(window)
            },
            show: {
                ready: true,
            },
            hide: {
                fixed: true,
                delay: 500
            },
            style: 'qtip qtip-default qtip-green qtip-shadow qtip-rounded qtip-pos-tl',
        });
    }
// end of script
})();
Das Signaturen Script welches an das PHP Script die Bilder sendet & in die Datenbank speichert:

Code:
// ==UserScript==
//   [MENTION=286917]name[/MENTION]          Report SRO Advertisting Signatur
//   [MENTION=1005418]namespace[/MENTION]     [url]http://tampermonkey.net/[/url]
//   [MENTION=1805674]Version[/MENTION]       0.1
//  [MENTION=3833773]Description[/MENTION]   Displaying a button to scan all the Signatur Images and show larger then 700 KB
// [MENTION=1332190]author[/MENTION]        Devsome
//  [MENTION=340885]match[/MENTION]         [url]https://www.tampermonkey.net/index.php?version=4.9&ext=dhdg&updated=true[/url]
//  [MENTION=551144]grant[/MENTION]         none
//   [MENTION=1474840]reQuire[/MENTION]       [url]http://code.jquery.com/jquery-3.4.1.min.js[/url]
//  [MENTION=1392090]include[/MENTION]       [url]https://www.elitepvpers.com/forum/*[/url]
//  [MENTION=1392090]include[/MENTION]       [url]http://www.elitepvpers.com/forum/*[/url]
// ==/UserScript==

(function() {
    'use strict';
    // start of script

    $('img[src*="/reply.gif"]').each(function () {
      $(this).parent().after(
        '<img id="scanSignatur" style="cursor: pointer" width="96" height="20" src="https://devsome.com/signatur.png" alt="Scan Signatur" border="0" title="Scan Signatur">'
      );
    });

    let state = false;
    let countFound = 0;
    $('#scanSignatur').click(function() {
      $(this).remove();
      $('[id^=post_signature_] img').each(function( index ) {
        let src = $(this).attr('src');
        let that = $(this);
        $.post({
           url: "https://devsome.com/signatur.php",
           data: { s: src, k: 'meinSecretToken' },
           async: false,
           success: function (data) {
             if(data.size > 700) {
               countFound += 1;
               state = true;
               let sig = that.parents('[id^=post_signature_]');

               sig.addClass('file-size-exceeded');
               sig.children().first().before(
                   $(document.createElement('span')).addClass('file-size-notification')
               );
               sig.find('.file-size-notification').text('Total File Size > 700 KB (' + 'msg' + ')');
               sig.css('background-color', 'rgba(237,20,61,0.1)');

               let post = sig.parents('[id^=post_message_]');
             }

           }
        }).done(function() {
          if(!state) {
            $("body").qtip({
                content: {
                    text: 'Alle Signaturen sind ok!',
                    title: 'Signatur',
                },
                position: {
                    my: "top",
                    at: "top",
                    target: $(window)
                },
                show: {
                    ready: true,
                },
                hide: {
                    fixed: true,
                    delay: 500
                },
                style: 'qtip qtip-default qtip-green qtip-shadow qtip-rounded qtip-pos-tl',
            });
          } else {
            $("body").qtip({
                content: {
                    text: 'Es gibt eine ' + countFound + ' Signatur die mehr als 700 KB haben!',
                    title: 'Signatur',
                },
                position: {
                    my: "top",
                    at: "top",
                    target: $(window)
                },
                show: {
                    ready: true,
                },
                hide: {
                    fixed: true,
                    delay: 500
                },
                style: 'qtip qtip-default qtip-red qtip-shadow qtip-rounded qtip-pos-tl',
            });
          }
        });
      });
    });

// end of script
})();
Das PHP Script welche die Bilder checkt, in die Datenbank speichert und ein response wieder gibt:

Code:
<?php
header('Access-Control-Allow-Origin: *');

$src = $_REQUEST['s'];
$key = $_REQUEST['k'];


if ($key === 'meinSecretToken') {

    session_start();
    $cfg['sql_host'] = 'localhost';
    $cfg['sql_user'] = 'sqlUsername';
    $cfg['sql_pass'] = 'sqlPassword';
    $cfg['sql_db'] = 'datenbank';


    $sqlLink = mysql_connect($cfg[sql_host], $cfg[sql_user], $cfg[sql_pass]);
    if (!$sqlLink) {
        die('Ups');
    }
    mysql_select_db($cfg[sql_db], $sqlLink);

    $query = mysql_query("select url, size from epvp_signatur where url='$src'");
    $result = mysql_num_rows($query);
    if ($result > 0) {
        $data = mysql_fetch_array($query);
        header('Content-Type: application/json');
        die(
        json_encode([
            'state' => false,
            'size' => $data['size'],
            'error' => 'Image exist in Database',
        ])
        );
    } else {
        $size = remote_filesize($src);
        $size = round($size / 1024);
        mysql_query("insert into epvp_signatur(url, size) values('$src', '$size')");
    }


    $size = remote_filesize($src);
    $size = round($size / 1024);
    header('Content-Type: application/json');

    if ($size >= 701) {
        die(json_encode([
            'state' => true,
            'size' => $size,
        ]));
    }
    die(json_encode([
        'state' => false,
        'size' => $size,
    ]));

} else {
    die ('Something is wrong');
}


function remote_filesize($url)
{
    static $regex = '/^Content-Length: *+\K\d++$/im';
    if (!$fp =  [MENTION=4155496]fopen[/MENTION]($url, 'rb')) {
        return false;
    }
    if (
        isset($http_response_header) &&
        preg_match($regex, implode("\n", $http_response_header), $matches)
    ) {
        return (int)$matches[0];
    }
    return strlen(stream_get_contents($fp));
}
Die Tabelle:

Code:
-- Erstellungszeit: 13. Mai 2020 um 18:53

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET   [MENTION=5761278]Old_[/MENTION]CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET   [MENTION=5761278]Old_[/MENTION]CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET   [MENTION=5761278]Old_[/MENTION]COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

-- --------------------------------------------------------

--
-- Tabellenstruktur für Tabelle `epvp_signatur`
--

CREATE TABLE `epvp_signatur` (
  `id` int(11) NOT NULL,
  `url` varchar(250) COLLATE latin1_german1_ci NOT NULL,
  `size` int(100) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german1_ci;

--
-- Indizes der exportierten Tabellen
--

--
-- Indizes für die Tabelle `epvp_signatur`
--
ALTER TABLE `epvp_signatur`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `url` (`url`);

--
-- AUTO_INCREMENT für exportierte Tabellen
--

--
-- AUTO_INCREMENT für Tabelle `epvp_signatur`
--
ALTER TABLE `epvp_signatur`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
/*!40101 SET CHARACTER_SET_CLIENT   [MENTION=5761278]Old_[/MENTION]CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS   [MENTION=5761278]Old_[/MENTION]CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION   [MENTION=5761278]Old_[/MENTION]COLLATION_CONNECTION */;
Ja ich weiß, dass mysql Befehle outdated sind, funktioniert aber wunderbar. Quick & Dirty. Gerne kann das jemand Anpassen.

Bilder:

07/23/2020 03:50 sL1Me#2
Geniales Script!
09/04/2020 16:43 florian0#3
Hab mal erweitert, dass er den Report-Teil auch einfügt, wenn man den User geblockt hat und den Post dann über den Button trotzdem anzeigt. Dazu hab ich einfach die vB Funktion PostBit_Init gehookt. Ich hab kein Plan was die macht, aber die wird ausgeführt wenn man nen Post nachläd.

Code:
    var originalInit = PostBit_Init;
    PostBit_Init = function(C, D) {
        let retVal = originalInit(C, D);

        let thePost = $('#post' + D);
        let theImage = thePost.find('img[title="Report Post"]').each(function(index) {
            addReportMenu(this);
        });

        return retVal;
    }
addReportMenu ist die Func die sonst als Lambda hier aufgerufen wurde:
Den Index hab ich entfernt, der war eh useless :kappa:

Code:
    $('img[title="Report Post"]').each(function(index) {
        addReportMenu(this);
    });

Im kompletten Script hab ich noch ein Feedback über die tatsächlich versendete Nachricht eingebaut. Will die Mods ja nicht zuspammen. Wenn man nix auswählt (auf "Choose" bleibt) fragt er einen nach der Nachricht die man abschicken möchte.

Damit is auch der "Bug" behoben, dass man immer erst was anderes auswählen musste wenn man den ersten Eintrag in der Liste verwenden wollte.

Wer das net mag kanns ja weglassen :P.

09/07/2020 19:57 Devsome#4
Habe das ganze mal auf GitHub gepackt

[Only registered and activated users can see links. Click Here To Register...]