TradeMe Add Report Flag to Category Index Items

Takes you straight to the report page. Has 2 matches because TradeMe is inconsistent with their use of upper and lower case

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         TradeMe Add Report Flag to Category Index Items
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Takes you straight to the report page. Has 2 matches because TradeMe is inconsistent with their use of upper and lower case
// @author       Sarah King
// @match        http://www.trademe.co.nz/browse/categorylistings.aspx*
// @match        http://www.trademe.co.nz/Browse/CategoryListings.aspx*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var splitUrl = function() {
        var vars = [], hash;
        var url = document.URL.split('?')[0];
        var p = document.URL.split('?')[1];
        if(p !== undefined){
            p = p.split('&');
            for(var i = 0; i < p.length; i++){
                hash = p[i].split('=');
                vars.push(hash[1]);
                vars[hash[0]] = hash[1];
            }
        }
        vars['url'] = url;
        return vars;
    };

    var getparams = splitUrl();
    var rptpath;

    if ("rptpath" in getparams){
        rptpath = splitUrl().rptpath;
    }
    else {
        rptpath = splitUrl().mcatpath;
    }

    //

    // Your code here...
    $('head').append('<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" type="text/css" />');
    $('head').append('<style type="text/css">div.title a.tmflag:visited {color: paleturquoise;}</style>');

    $(".supergrid-listing").each(function(){
        if (!$( this ).hasClass( "no-listing" )){
            var watchlistId = $(this).children('.watchlist').first();                    
            var auction = watchlistId.attr('id').substr(9);         
            $(this).children('.info').children('.title').html('<a href="/Browse/CommunityWatch.aspx?id='+auction+'&rptpath='+rptpath+'" class="tmflag" target="_blank"><i class="fa fa-flag"></i></a> ' + $(this).children('.info').children('.title').html());
        }
    });
})();