// ==UserScript==
// @name SGW Fixer*
// @namespace https://greasyfork.org
// @include https://sellers.shopgoodwill.com/sellers/newAuctionItem-catsel.asp*
// @include https://sellers.shopgoodwill.com/sellers/reviewItem-label.asp*
// @include https://sellers.shopgoodwill.com/sellers/reviewItem-label.asp?state=2
// @include https://sellers.shopgoodwill.com/sellers/fileUpload/renform-jquery-catsel.asp
// @version 7.2.2.5
// @description Implements numerous improvements to the functionality of the Shopgoodwill seller site.
// @grant none
// @require https://greasyfork.org/scripts/23449-gm-api-script/code/GM%20API%20script.js?upDate=2016_09_23
// @require https://greasyfork.org/scripts/23451-sgw-shelves-cats/code/SGW%20Shelves%20%20Cats.user.js?upDate=2017_08_23
// @require https://greasyfork.org/scripts/23450-sgw-fixer-users/code/SGW%20Fixer%20-%20Users.js?upDate=2018_01_09
// @downloadURL none
// ==/UserScript==
var cyberMondayDate = 27; // Cyber Monday 2017 is November 27th, hence 27;
var cyberMondayAuctionDuration = 7; // If any CM items are posted as auctions, how long should they run?
$('*[name]').not('[id]').each(function(){
$(this).attr('id', $(this).attr('name'));
});
if ($('input[name="authentic"]').length) {
$('input[name="authentic"]').attr('checked', true);
}
window.addEventListener ("message", receiveMessage, false);
var url = document.URL;
var premium = false;
var baseDuration = 0;
var defaultStartingBid = $('#itemMinimumBid').val();
var defaultCarrier = $('#itemShipMethod').val();
var defaultDuration = $('#itemDuration').val();
if (url.indexOf('skip=skip') >= 0) {
$('input[name="submit"]').trigger('click');
}
//$('a:contains("Seller\'s Guide")').replaceWith("Seller\'s Guide");
function receiveMessage (event) {
var messageJSON;
try {
messageJSON = JSON.parse (event.data);
}
catch (zError) {
// Do nothing
}
var safeValue = JSON.stringify(messageJSON);
if (typeof(messageJSON['lastLocation'])!== "undefined") {
GM_setValue("lastLocation", safeValue);
} else {
GM_setValue("storedPresets", safeValue);
}
}
if (url == "https://sellers.shopgoodwill.com/sellers/reviewItem-label.asp?state=2") {
var myLastLoc = JSON.parse(GM_getValue("lastLocation", ""));
if (typeof myLastLoc !== "undefined") {
$('a:contains("Add")').before("Location: " + myLastLoc['lastLocation'] + "
");
$('a:contains("Add")').attr('href', "https://sellers.shopgoodwill.com/sellers/fileUpload/renform-jquery-catsel.asp");
$('p').first().before("
" + myLastLoc['lastTitle'] + "
");
GM_deleteValue("lastLocation");
}
} else if (url == "https://sellers.shopgoodwill.com/sellers/fileUpload/renform-jquery-catsel.asp") {
window.setInterval(function(){
if (($('.template-download:visible').length > 0) && ($('.template-upload:visible').length <= 0)) {
$('#btnSubmit').trigger('click');
}
}, 20000);
}
if (GM_getValue("lastLocation")) {
myLastLoc = JSON.parse(GM_getValue("lastLocation", ""));
}
// this next section gets us all the locations, from the script tag where SGW defines them
var scripTags = document.getElementsByTagName('script');
var allScripTags = '';
if (scripTags.length > 0) {
Array.prototype.forEach.call(scripTags, function(el){
allScripTags += el.outerHTML;
});
if (allScripTags.indexOf('jsondata2') >= 0) {
allScripTags = allScripTags.substring(allScripTags.indexOf('jsondata2'));
allScripTags = allScripTags.substring(allScripTags.indexOf('['));
allScripTags = allScripTags.substring(0, allScripTags.indexOf(';'));
}
}
var locations = JSON.parse(allScripTags);
var validLocations = [];
locations.forEach(function(locationObject){
// document.getElementById('locationList').innerHTML += '';
if (locationObject.label.toLowerCase() != 'not assigned') {
validLocations.push(locationObject.label);
}
});
var validCategories = [];
var categoryIds = {};
$.getJSON('https://images.shopgoodwill.com/Catlistjsonbuyer.txt', {}, function(JsonData){
$.each(JsonData, function(index, object) {
validCategories.push(object.label);
categoryIds[object.label] = object.id;
})
});
function format(item) {
var cell = '';
cell += item.label;
return cell;
}
// The name as listed is what the script looks for at the top of the page, as in "Welcome Firstname Lastname".
// (Any piece of that is fine: "John L", "John Linnell", and "hn Lin" would all pick out John Linnell)
var thisPoster = "";
var myPosterName = "";
var posterDelay = 0;
$.each(posters, function(name, info) { //working 10/27
re = new RegExp(name,"gi");
if(re.exec($(".smtext").html())) {
thisPoster = name.replace(/ /gi,"");
myPosterName = name;
console.log(thisPoster);
}
});
var presetTypes = {
"Title" : "",
"Category" : "",
"Store" : "",
"Shipping Weight" : "",
"Display Weight" : "",
"Location" : "",
"Duration" : "",
"Starting Bid" : "",
"BIN Price" : "",
"Ship Charge" : "",
"Ship Type" : "",
// ^^^ general, guitar, art, lot, long, Media <---- note the capital M!
// "Ship in own box/between cardboard" : "",
// ^^^ yes for yes, any other value defaults to no
"Dimension 1" : "",
"Dimension 2" : "",
"Dimension 3" : "",
"Skip" : "",
"Owner" : "",
"Description" : "",
}
var cyberMondayPosters = ["Holden"/*collectibles & jewelry*/, "Jackie", "Alicia", "Jacob"];
var welcomeText = $('table:contains("Welcome")').text();
var cyberMondayPoster = false;
$.each(cyberMondayPosters, function(cmIndex, cmPoster) {
if (welcomeText.indexOf(cmPoster) >= 0) {
// presetTypes['Cyber Monday'] = "";
cyberMondayPoster = true;
}
});
if (GM_getValue("storedPresets")) {
var presets = JSON.parse (GM_getValue("storedPresets"));
if (!presets.hasOwnProperty('Owner') || presets['Owner'] != thisPoster) {
presets = {
"Title" : "",
"Category" : "",
"Store" : "",
"Shipping Weight" : "",
"Display Weight" : "",
"Location" : "",
"Duration" : "",
"Ship Charge" : "",
"Ship Type" : "",
// ^^^ general, guitar, art, lot, long, Media <---- note the capital M!
// "Ship in own box/between cardboard" : "",
// ^^^ yes for yes, any other value defaults to no
"Dimension 1" : "",
"Dimension 2" : "",
"Dimension 3" : "",
"Skip" : "",
"Owner" : thisPoster,
// "Cyber Monday" : "",
"Description" : "",
};
} else {
if (!presets.hasOwnProperty('Duration')) {
presets['Duration'] = "";
}
}
} else {
var presets = {
"Title" : "",
"Category" : "",
"Store" : "",
"Shipping Weight" : "",
"Display Weight" : "",
"Location" : "",
"Duration" : "",
"Starting Bid" : "",
"BIN Price" : "",
"Ship Charge" : "",
"Ship Type" : "",
// ^^^ general, guitar, art, lot, long, Media <---- note the capital M!
// "Ship in own box/between cardboard" : "",
// ^^^ yes for yes, any other value defaults to no
"Dimension 1" : "",
"Dimension 2" : "",
"Dimension 3" : "",
"Skip" : "",
"Owner" : thisPoster,
// "Cyber Monday" : "",
"Description" : "",
};
}
if(presets['Skip'] == 'skip' || url.indexOf('skip=skip') >= 0) {
// console.log('Skip==skip');
if (url.indexOf('newauctionitem-catsel.asp')) {
document.getElementById('form1').action = document.getElementById('form1').action + '?skip=skip';
} else {
$('form').each(function(){
if ($(this)[0].action.indexOf('?') < 0) {
$(this)[0].action += '?skip=skip';
} else {
$(this)[0].action += '&skip=skip';
}
});
}
}
var myPresets = "";
var presetBox = "Set presets:
";
$('p:contains("photos are uploaded")').after(presetBox);
var presetTimeout = window.setTimeout(function(){
$.each(presetTypes, function(key, value){
var myVal = presets[key];
if (typeof myVal == 'undefined' || myVal == 'undefined' || myVal.length < 1) {
myVal = '';
}
if (myVal && myVal.length) {
myPresets += "" + key + ": " + myVal + "
";
}
key2 = "" + key + ""
if (key == 'Ship Type') {
key2 += " (guitar, art, long, media, clothing, pickup)";
} else if (key == "Ship in own box/between cardboard") {
// key2 = "Own box/cardboard: (yes or blank/no)";
}
key2 += ": ";
if (key == 'Description') {
$('#presetBox').append('');
$('#presetDescription').html(myVal);
} else {
$('#presetBox').append("" + key2 + "
");
}
});
$('#presetCategory').replaceWith($('#catID').clone().attr('id', 'presetCategory'));
// $('#presetCategory').autocomplete("search", $('#presetCategory').val());
$('#presetCategory').autocomplete({
source: validCategories,
minLength: 0,
select: function (event, ui) {
$('#presetCategory').val(ui.item.label);
// $('#catid').val(ui.item.id);
// $('#catid').val(categoryIds[ui.item.label]);
console.dir(ui.item);
$('#presetCategory').blur();
return false;
}
})
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "" )
.data("ui-autocomplete-item", item)
.append("" + format(item) + "")
.appendTo(ul);
};
$('#presetCategory').bind('click', function(){
$('#presetCategory').autocomplete('search', "");
});
$('#presetInputOwner').hide();
if (myPresets.length) {
myPresets = "Presets:
" + myPresets + "
";
$('#presetBox').before(myPresets);
$('#myPresets').data("data", presets);
}
if(myPresets['Ship Type'] == "media") {
myPresets['Ship Type'] = "Media";
}
$('#presetBox').append("
Update presets");
$('#presetBox').append("
Clear presets");
$('#presetBox').after("
Edit presets");
$('#updatePresetsButton').bind('click', function(){
var presetList = ['Title', 'Skip', 'Category', 'Store', 'Shipping Weight', 'Display Weight', 'Location', 'Duration', 'Starting Bid', 'BIN Price', 'Ship Charge', 'Ship Type', 'Dimension 1', 'Dimension 2', 'Dimension 3', 'Owner',/* 'Cyber Monday'*/];
var presetVals = {};
$.each(presetList, function(key, value){
presetVals[value] = $('[id="preset' + value + '"]').val();
myValue = $('[id="preset' + value + '"]').val();
});
if ($('#presetDescription').html().length >= 1) {
presetVals['Description'] = $('#presetDescription').html();
} else {
presetVals['Description'] = '';
}
$('#myPresets').remove();
var myPresets = {};
$.each(presetVals, function(key, value){
if (value.length) {
myPresets += '' + key + ': ' + value + '
';
}
});
if(myPresets['Ship Type'] == "media") {
myPresets['Ship Type'] = "Media";
}
var messageTxt = JSON.stringify (presetVals);
window.postMessage (messageTxt, '*');
if (myPresets.length) {
myPresets = "Presets:
" + myPresets + "
";
$('#presetBox').before(myPresets);
$('#myPresets').data('data', presetVals);
$('#myPresets').html($('#myPresets').html().replace('undefined',''));
$('#myPresets').html($('#myPresets').html().replace('[object Object]',''));
}
$("#presetBox").hide();
$("#presetBoxButton").show();
processPresets(presetVals);
});
$('#clearPresetsButton').bind('click', function(){
var skipVal = $('#presetSkip').val();
$('.presetInput, #presetCategory, #presetStore, #presetLocation').not('#presetSkip').each(function(){
$(this).val('');
});
$('#presetDescription').html('');
// processpresets
$('#itemTitle, #catID, #itemsellerstore, #itemWeight, #itemDisplayWeight, #itemSellerInventoryLocationID, .gesMN_input').val('');
$('#itemBuyNowPrice, #itemShippingPrice').val('0');
var iframe = document.getElementById('WebWizRTE').contentDocument || document.getElementById('WebWizRTE').contentWindow.document;
var description = iframe.querySelectorAll('body')[0];
description.innerHTML = '';
$('#itemShipMethod').val(defaultCarrier);
$('#itemMinimumBid').val(defaultStartingBid);
$('#itemDuration').val(defaultDuration);
$('#presetSkip').val(skipVal);
$("#presetBox").hide();
$("#presetBoxButton").show();
});
if ($('#presetSpanDescription').length > 0) {
$('#presetSpanDescription').css({
'position' : 'relative',
'left' : '25px',
});
$('#presetSpanDescription > b').first().css({
'position' : 'relative',
'left' : '-25px',
});
$('#myPresets').append("");
$('.presetSpan').not('#presetSpanDescription').appendTo('#presetTd1');
$('#presetSpanDescription').appendTo('#presetTd2');
$('#myPresets').css('width', '420px');
}
$('#presetLocation').attr('id', 'tempLoc');
$('#tempLoc').after("");
$('#tempLoc').remove();
$('#presetLocation').append("");
$.each(jsondata2, function(shelfIndex, shelfArray){
$('#presetLocation').append("");
});
$('#presetStore').attr('id', 'tempStore');
$('#tempStore').after($('#itemsellerstore').clone().attr('id', 'presetStore'));
$('#tempStore').remove();
$('#presetStore').prepend("");
$('#catID').autocomplete({
source: validCategories,
minLength: 0,
select: function (event, ui) {
$('#catID').val(ui.item.label);
// $('#catid').val(ui.item.id);
// $('#catid').val(categoryIds[ui.item.label]);
console.dir(ui.item);
$('#catID').blur();
$('#WebWizRTE').focus();
return false;
}
})
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "" )
.data("ui-autocomplete-item", item)
.append("" + format(item) + "")
.appendTo(ul);
};
$('#itemSellerInventoryLocationID').autocomplete({
source: validLocations,
minLength: 0,
select: function (event, ui) {
$('#itemSellerInventoryLocationID').val(ui.item.label);
return false;
}
})
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "" )
.data("ui-autocomplete-item", item)
.append("" + format(item) + "")
.appendTo(ul);
};
$('#catID').bind('focus', function(){
$('#catID').autocomplete("search", $('#catID').val());
});
$('#itemSellerInventoryLocationID').bind('focus', function(){
$('#itemSellerInventoryLocationID').autocomplete("search", $('#itemSellerInventoryLocationID').val());
});
var quickCatsTable = document.createElement('table');
document.getElementById('itemTitle').parentNode.appendChild(quickCatsTable);
quickCatsTable.innerHTML = "| Quick Categories: | |
"
//quickCatsContainer.id = 'quickCatsContainer';
var quickCatsContainer = document.getElementById('quickCatsContainer');
//quickCatsTable.outerHTML = '
' + quickCatsTable.outerHTML;
quickCatsTable.style.marginTop = '10px';
$.each(myCats, function(groupName, groupObject) {
var quickCats = document.createElement('select');
quickCats.id = 'quickCats-'+groupName.replace(' ','_');
quickCats.className += 'quickCat';
quickCats.style.margin = '4px';
quickCats.style.width = '110px';
quickCats.appendChild(document.createElement('option'));
quickCats.querySelectorAll('option')[0].innerHTML = groupName;
quickCats.querySelectorAll('option')[0] = 'default';
// console.log(groupName);
// console.dir(groupObject);
// Not sure why I can't get this to work with Array.prototype....
$.each(groupObject, function(catName, catValue) {
var myOption = document.createElement('option');
myOption.innerHTML = " " + catName;
myOption.value = catValue;
quickCats.appendChild(myOption);
});
// quickCats.appendChild(myOptGroup);
if (document.querySelectorAll('.quickCat').length%4 == 0 && document.querySelectorAll('.quickCat').length > 0) {
quickCatsContainer.appendChild(document.createElement('br'));
}
quickCatsContainer.appendChild(quickCats);
// quickCats.outerHTML = '
Quick categories: ' + quickCats.outerHTML;
quickCats.onchange = function(){
var catID = document.getElementById('catID');
catID.value = quickCats.value;
catID.focus();
$('#catID').autocomplete("search", quickCats.value);
// console.dir(categoryIds);
if (categoryIds.hasOwnProperty(quickCats.value)) {
// document.getElementById('catid').value = categoryIds[quickCats.value];
}
quickCats.className += ' activeQuickCats';
var allCatMenus = document.querySelectorAll('.quickCat');
Array.prototype.forEach.call(allCatMenus, function(el) {
el.style.border = '';
/*
if (el.className.indexOf('activeQuickCats') < 0) {
el.value = 'default';
} else {
console.log(e.className);
}
el.className = el.className.replace('activeQuickCats', '');
//*/
});
quickCats.style.border = '2px solid #5e5';
// quickCats.style.backgroundColor = '#afa';
}
});
// console.dir(myPresets);
}, 1000);
if(url == "https://sellers.shopgoodwill.com/sellers/newAuctionItem-catsel.asp?clear=yes") {
// Hides form if photos are not uploaded
// the return URL from the photo uploader is:
// https://sellers.shopgoodwill.com/sellers/newauctionitem-catsel.asp?btnSubmit=Return+to+item+entry
$('#form1').hide();
} else if (url != "https://sellers.shopgoodwill.com/sellers/reviewItem-label.asp") {
$('#itemTitle').parent().parent().prepend("");
$('#listingUpgrades').append("Gallery ($8) | ");
$('#listingUpgrades').append("Feature ($5) | ");
$('#listingUpgrades').append("Premium item | ");
$('#listingUpgrades').parent().append("| Duration: (ends on a ) |
");
$('#listingUpgrades').parent().append("| Starting Price: |
");
}
//$("#form1").append("");
$("#form1").append("false
");
//$("#form1").append("");
var button1 = "');
$('#itemShipMethod').before('');
$('#itemShipMethod').after("
" + button1 + "Unlock shipping method" + button2 + "
");
}
var currentDur = $('#itemDuration').val();
if (url != "https://sellers.shopgoodwill.com/sellers/newauctionitem-catsel.asp?btnSubmit=Return+to+item+entry" && url != "https://sellers.shopgoodwill.com/sellers/reviewItem-label.asp") {
$('#itemDuration').replaceWith("");
}
var cmAllow = "no";
var cmBIN = "no";
$("#itemStartOffset, #itemstarttime, #itemDuration, #itemEndTime, #itemShipMethod, #itemShippingPrice, #itemNoCombineShipping, #itemAutoInsurance").attr('tabindex', "-1");
$("#WebWizRTE, #itemDescription").height(700);
$("#WebWizRTE, #itemDescription").width(810);
$("#catID").attr("size", 100);
$("strong:contains('Item Title')").prepend("
");
$("#itemTitle").attr("maxlength",50);
$("#itemTitle").removeAttr('onkeypress').removeAttr('onkeyup');
$('#myCounter').html(50);
//UGH, SHOPGOODWILL
$('font:contains("Numbers and decimal point")').after("
" + button1 + "Unlock shipping charge" + button2 + "
");
$('strong:contains("Private Description")').hide();
$('#itemSellerInfo').hide();
$('p:contains("optimization")').hide();
var html = $('#form1 > table > tbody > tr:eq(1) > td:eq(1)')[0];
var html2 = $('#form1 > table:eq(1) > tbody > tr > td')[0];
html2.innerHTML = html2.innerHTML.replace(/You will be advised[\s\S]*place your listing[\s\S]*will be assessed[\s\S]*in the next screen\./g,"");
$("p:contains('Make sure you know')").hide();
$("p:contains('Please review the')").hide();
$("p:contains('read shopgoodwill')").hide();
$("hr").hide();
$('p:contains("Starting Bid")').addClass("bidStartDurBox");
$('p:contains("Auction Duration")').addClass("bidStartDurBox").after("
");
$('p:contains("Auction Duration")').after("Starting bid, start time, duration
")
$('#bidStartDurBoxButton').after("Buy now price");
$('.bidStartDurBox').hide();
$('#itemStartOffset').attr("id", "itemStartOffset");
$('#itemstarttime').attr("id", "itemstarttime");
$('#itemDuration').attr("id", "itemDuration");
html.innerHTML = html.innerHTML.replace("onblur", "alt");
html.innerHTML = html.innerHTML.replace(/
/g,"");
html.innerHTML = html.innerHTML.replace(/pounds((.|\n)*)oversized packages\./g,"");
html.innerHTML = html.innerHTML.replace(/Shipping Charge allows((.|\n)*)United States\./g,"");
$('b:contains("Set the Shipping Charge")').hide();
html.innerHTML = html.innerHTML.replace(/to use the default shipper's rate calculator\./g,"");
html.innerHTML = html.innerHTML.replace(/This is the number((.|\n)*)become active\./g,"");
html.innerHTML = html.innerHTML.replace(/This is the number((.|\n)*)will end\./g,"");
$('font:contains("UPS dimensional weight calculator click")').hide();
html.innerHTML = html.innerHTML.replace(/Select this option to change the shipping method from your default method\./g,"");
html.innerHTML = html.innerHTML.replace(/One line((.|\n)*)find your item\.|You may use((.|\n)*)do not use HTML\.|For |Dutch auctions((.|\n)*)selling a single set\.|This is the price((.|\n)*)and commas \(','\)|Bid increment is((.|\n)*)each bid\.|Reserve Price is((.|\n)*)Reserve Price!|Buy Now allows((.|\n)*)Buy Now!/g, "");
html.innerHTML = html.innerHTML.replace(/Item Quantity((.|\n)*)itemQuantity" size="3" value="1">/g, "");
html.innerHTML = html.innerHTML.replace(/per item((.|\n)*): 3\.00/g, "");
html.innerHTML = html.innerHTML.replace(/Bid Increment((.|\n)*)10\.00/g, "Bid increment:
Reserve price:
Buy now price: (leave at 0 to not have buy-it-now as an option)
Starting bid = BIN price");
html.innerHTML = html.innerHTML.replace(/Box Selection((.|\n)*)willing to ship your item\./g, "")
html.innerHTML = html.innerHTML.replace(/Handling Charge((.|\n)*)final item selling price\)\./g, "");
html.innerHTML = html.innerHTML.replace(//g, "");
html.innerHTML = html.innerHTML.replace(/Example: 1<\/i>/g, "");
html.innerHTML = html.innerHTML.replace(/here<\/a>/g, "here");
html.innerHTML = html.innerHTML.replace(/here<\/a>/g, "here");
html.innerHTML = html.innerHTML.replace(/