SGW Item Modification Helper

Improves the modification page

  1. // ==UserScript==
  2. // @name SGW Item Modification Helper
  3. // @namespace greasyfork.org
  4. // @version 1.4.0.9
  5. // @grant none
  6. // @include https://sellers.shopgoodwill.com/sellers/modifyItem.asp*
  7.  
  8. // @require https://greasyfork.org/scripts/37273-underdollar-jquery-replacement/code/Underdollar%20jQuery%20replacement.js?upDate=2018_01_11sq2
  9. // @description Improves the modification page
  10. // ==/UserScript==
  11.  
  12.  
  13. console.log('squirrel?')
  14.  
  15. // @require https://greasyfork.org/scripts/23449-gm-api-script/code/GM%20API%20script.js?upDate=2016_09_23
  16.  
  17. //NodeList.prototype.forEach = Array.prototype.forEach;
  18.  
  19. //Array.prototype.forEach.call(document.querySelectorAll('*[name]'), function(el) {
  20. document.querySelectorAll('*[name]').forEach(function(el) {
  21. if (typeof el.id == 'undefined' || el.id.length < 1) {
  22. el.id = el.getAttribute('name');
  23. }
  24. });
  25.  
  26.  
  27.  
  28.  
  29. _$('#itemTitle').parent().parent().parent().hide();
  30. _$('#itemTitle').parent().parent().parent().before("<tr><td valign='top' width='10' bgcolor='#2045A3'><img src='../images/spacer.gif' height=' 0' width='10'></td><td id='contentTD'></td></tr>");
  31.  
  32. _$('#contentTD').append("<p id='itemTitleContainer'><b>Item Title:</b> </p>");
  33. _$('#itemTitleContainer').append(_$('#itemTitle'));
  34.  
  35. _$('#contentTD').append("<p id='itemCategoryContainer'><b>Category:</b> </p>");
  36. _$('#itemCategoryContainer').append(_$('#s1'));
  37.  
  38. _$('#contentTD').append("<p id='itemDescriptionContainer'><b>Description:</b> </p>");
  39. _$('#itemDescriptionContainer').append(_$('#colourPalette').parent());
  40.  
  41. _$('#contentTD').append("<div id='itemShippingDetailsContainer'></div>");
  42. _$('#itemShippingDetailsContainer').append("<p id='itemShippingWeightContainer'><b>Shipping Weight:</b> </p>");
  43. _$('#itemShippingWeightContainer').append(_$('#itemWeight'));
  44. _$('#itemShippingDetailsContainer').append("<p id='itemDisplayWeightContainer'><b>Display (Actual) Weight:</b> </p>");
  45. _$('#itemDisplayWeightContainer').append(_$('#itemDisplayWeight'));
  46. _$('#itemShippingDetailsContainer').append("<p id='itemShippingPriceContainer'><b>Shipping Charge:</b><br></p>");
  47. _$('#itemShippingPriceContainer').append(_$('#itemShippingPrice'));
  48. _$('#itemShippingDetailsContainer').append("<p id='itemShipMethodContainer'><b>Shipping Method:</b> <br></p>");
  49. _$('#itemShipMethodContainer').append(_$('#itemShipMethod'));
  50. _$('#itemShippingDetailsContainer').append("<p id='itemNoCombineShippingContainer'><b>Item Shipment Combining:</b><br></p>");
  51. _$('#itemNoCombineShippingContainer').append(_$('#itemNoCombineShipping'));
  52. _$('#itemNoCombineShippingContainer').append(" Select this option if the buyer of this item should not be allowed to combine this item with shipment of other items.");
  53. _$('#itemShippingDetailsContainer').append("<p id='itemAutoInsuranceContainer'><b>Auto Include Insurance (USPS Only):</b></p>");
  54. _$('#itemAutoInsuranceContainer').append(_$('#itemAutoInsurance'));
  55.  
  56. _$('#contentTD').append("<p id='itemsellerstoreContainer'><b>Seller Store:</b> </p>");
  57. _$('#itemsellerstoreContainer').append(_$('#itemsellerstore'));
  58.  
  59. //_$('#itemSellerInventoryLocationID').parent().attr('id', 'itemSellerInventoryLocationIDContainer').appendTo(_$('#contentTD')); // no appendTo, appendTo is stupid
  60. _$('#contentTD').append(_$('#itemSellerInventoryLocationID').parent().attr('id', 'itemSellerInventoryLocationIDContainer'));
  61.  
  62. _$('#contentTD').append("<p id='itemSellerInfoContainer'><b>Seller Private Description:</b><br></p>");
  63. _$('#itemSellerInfoContainer').append(_$('#itemSellerInfo'));
  64.  
  65. _$('#contentTD').append("<p style='position:relative; left: 10px; padding-bottom:4px;'><span class='fakeButton' onclick='_$(\"#hiddenJunk\").toggle();'>Show/hide hidden fields/etc.</span></p>");
  66.  
  67.  
  68. _$('#contentTD').parent().after("<tr style='display:none;' id='hiddenJunk'><td valign='top' width='10' bgcolor='#2045A3'><img src='../images/spacer.gif' height=' 0' width='10'></td><td id='hiddenJunkTD'></td></tr>");
  69.  
  70. _$('#hiddenJunkTD').append("<p id='itemQuantityContainer'><b>Item Quantity: </b></p>");
  71. _$('#itemQuantityContainer').append(_$('#itemQuantity').parent());
  72.  
  73. _$('#hiddenJunkTD').append("<p id='itemMinimumBidContainer'><b>Minimum Bid: </b></p>");
  74. _$('#itemMinimumBidContainer').append(_$('#itemMinimumBid').parent());
  75.  
  76. _$('#hiddenJunkTD').append("<p id='itemBidIncrementContainer'><b>Bid Increment: </b></p>");
  77. _$('#itemBidIncrementContainer').append(_$('#itemBidIncrement').parent());
  78.  
  79. _$('#hiddenJunkTD').append("<p id='itemReserveContainer'><b>Reserve Price: </b></p>");
  80. _$('#itemReserveContainer').append(_$('#itemReserve').parent());
  81. _$('#itemReserve').parent().children().first().remove();
  82.  
  83. _$('#hiddenJunkTD').append("<p id='itemBuyNowPriceContainer'><b>Buy Now Price: </b></p>");
  84. _$('#itemBuyNowPriceContainer').append(_$('#itemBuyNowPrice').parent());
  85. _$('#itemBuyNowPrice').parent().children().first().remove();
  86.  
  87. _$('#hiddenJunkTD').append("<p id='itemActualDimensionsContainer'></p>");
  88. _$('#itemActualDimensionsContainer').append(_$('#itemLength').parent().parent().parent());
  89.  
  90. _$('#hiddenJunkTD').append("<p id='itemShippingDimensionsContainer'></p>");
  91. _$('#itemShippingDimensionsContainer').append('<font face="Arial" size="2"><strong>Shipping Dimension - Length x Width x Height in inches (optional)</font><font face="arial" color="#a3223a" size="4"></font>:</strong>');
  92. _$('#itemShippingDimensionsContainer').append(_$('#itemShipLength'));
  93. _$('#itemShippingDimensionsContainer').append(" <font face='Arial' size='2'>(Numbers and decimal point '.' only) Used for shipping optimization and prevention of oversized charges.</font>");
  94.  
  95. _$('#hiddenJunkTD').append("<p id='itemShippingContainer'><b>Shipping: </b><p>");
  96. _$('#itemShippingContainer').append(_$('#itemShipping'));
  97. _$('#itemShippingContainer').append(_$('select[name="itemShipping"]'));
  98.  
  99. _$('#hiddenJunkTD').append("<p id='itemHandlingPriceContainer'><b>Handling Charge: </b></p>");
  100.  
  101. _$('#itemHandlingPriceContainer').append(_$('#itemHandlingPrice').parent());
  102. _$('#itemHandlingPrice').parent().children().first().remove();
  103.  
  104. _$('#hiddenJunk').after("<tr><td valign='top' width='10' bgcolor='#2045A3' height='10px'><img src='../images/spacer.gif' height=' 0' width='10'></td><td id='hiddenJunkTD'></td></tr>");
  105.  
  106. _$('#itemShipMethod option[value="3"]').text('Post Office');
  107.  
  108.  
  109. _$('#itemTitleContainer').after('<div id="counterContainer"><font face="Arial" size="4">You have <b><span id="myCounter"></span></b> characters remaining.</font></div>');
  110. _$("#myCounter").html(50-_$('#itemTitle').val().length);
  111. _$('#itemTitle').bind('keyup', function(){
  112. _$("#myCounter").html(50-_$('#itemTitle').val().length);
  113. });
  114.  
  115. // --------- Shipping calculator --------------------------------------------
  116.  
  117. if (_$('#gesMN_shippingCalculatorContainer').length > 0) {
  118. _$("#itemDescriptionContainer").append(_$('#gesMN_shippingCalculatorContainer'));
  119. var sgwTimeouts = window.setTimeout(function(){
  120.  
  121.  
  122. function combineCheck(){
  123. var noCombine = false;
  124. var myWeight = _$('#itemWeight').val();
  125. if (myWeight >= 20) {
  126. console.log('badWeight: >= 20');
  127. noCombine = true;
  128. } else if (_$('#combineCheck').html() != 'true') {
  129. var myCat = _$('#s1').val();
  130. var badCats = ['Paintings', 'Prints', 'Strings', 'Brass', 'Formalwear', 'Outerwear', 'Wedding > Dresses', 'Lamps', 'Dinnerware', 'Sewing Machines', 'Typewriters', 'Receivers', 'Turntables', 'Dinnerware', 'Trains'];
  131. _$.each(badCats, function(index, category){//__$.each == __$().each
  132. if (myCat.indexOf(category) >= 0) {
  133. noCombine = true;
  134. console.log('badCat: ' + category);
  135. }
  136. });
  137. if (noCombine == false) {
  138. var myDescription = '';
  139. if (typeof _$('#WebWizRTE').contents()[0]['body']['innerText'] != 'undefined') { // this may not work
  140. var myDesc = _$('#WebWizRTE').contents()[0]['body']['innerText'].replace(/(?:\r\n|\r|\n)/g, '').toLowerCase();
  141. }
  142. var myTitle = _$('#itemTitle').val().toLowerCase();
  143. var badWords = ['Framed', 'Saxophone', 'Guitar', 'Keyboard', 'Trombone', 'Telescope', 'Saxophone', 'Lamp', 'Snowboard', 'Skateboard', 'Glass', 'Crystal', 'Cast iron', 'Tool', 'Drum', 'Sewing machine', 'Typewriter', 'Printer', 'Desktop', 'Receiver', 'Turntable', 'Monitor'];
  144. // console.log(myDescription);
  145. // console.log(myTitle);
  146. _$.each(badWords, function(index, word){
  147. word = word.toLowerCase();
  148. if (myDescription.indexOf(word) >= 0 || myTitle.indexOf(word) >= 0) {
  149. noCombine = true;
  150. console.log('badWord: '+word);
  151. } else {
  152. }
  153. });
  154. if (noCombine == false && (myCat.indexOf('Speaker') >= 0 || myTitle.indexOf('speaker') >= 0 || myDescription.indexOf('speaker') >= 0) && myWeight > 5) {
  155. noCombine = true;
  156. console.log('badWeight (speaker)');
  157. }
  158. }
  159. }
  160. if (noCombine == true) {
  161. console.log('no combine');
  162. _$('#itemNoCombineShipping').attr('checked', true);
  163. } else {
  164. console.log('combine');
  165. _$('#itemNoCombineShipping').attr('checked', false);
  166. }
  167. }
  168.  
  169. function dummyWeight() {
  170. if (_$('#itemWeight').val().length < 1) {
  171. _$('#itemWeight').val(1);
  172. }
  173. if (_$('#itemDisplayWeight').val().length < 1) {
  174. _$('#itemDisplayWeight').val(1);
  175. }
  176. }
  177.  
  178. function setCombinable(bool) {
  179. // true == CAN be combined; false == CANNOT
  180. _$('#combineCheck').html(bool);
  181. if (bool === true || bool == 'true') {
  182. _$('itemNoCombineShipping').attr('checked', false);
  183. } else {
  184. _$('itemNoCombineShipping').attr('checked', true);
  185. }
  186. }
  187. function getElement(queryString) {
  188. if (queryString.indexOf('#') == 0) {
  189. return document.getElementById(queryString.replace('#',''));
  190. } else {
  191. return document.querySelectorAll(queryString)[0];
  192. }
  193. }
  194. function getElements(queryString) {
  195. return document.querySelectorAll(queryString);
  196. }
  197. function hide(el){
  198. el.style.display = 'none';
  199. el.classList += 'gesHidden';
  200. return false;
  201. }
  202. function show(el){
  203. el.style.display = '';
  204. return false;
  205. }
  206. function addCSS(element, styleText) {
  207. element.style.cssText +=';'+ styleText;
  208. return false;
  209. }
  210.  
  211.  
  212. _$('#gesMN_useThisButton').bind('click', function(){
  213. var method;
  214. var actualWeight = _$('#gesMN_actualWeight').val();
  215. var shippingWeight = 0;
  216. var shippingCharge = 0;
  217. console.log(actualWeight);
  218. if (_$('#gesMN_shippingWeight').filter(function(el){
  219. return _$(el).isVisible();
  220. }).length > 0) {
  221. shippingWeight = _$('#gesMN_shippingWeight').html();
  222. _$('#itemShipMethod').val(2);
  223. _$('#itemAutoInsurance').attr('checked', false);
  224. console.log(shippingWeight);
  225. } else if (_$('#gesMN_shippingCharge').filter(function(el){
  226. return _$(el).isVisible();
  227. }).length > 0) {
  228. shippingWeight = actualWeight;
  229. _$('#itemShipMethod').val(3);
  230. _$('#itemAutoInsurance').attr('checked', true);
  231. shippingCharge = _$('#gesMN_shippingCharge').html();
  232. } else {
  233. shippingWeight = actualWeight;
  234. _$('#itemShipMethod').val(0);
  235. _$('#itemAutoInsurance').attr('checked', false);
  236. }
  237. _$('#itemWeight').val(shippingWeight);
  238. _$('#itemDisplayWeight').val(actualWeight);
  239. _$('#itemShippingPrice').val(shippingCharge);
  240. });
  241.  
  242. }, 1100);
  243.  
  244. }
  245.  
  246. _$('.fakeButton').css({
  247. 'border' : '1px solid #CCC',
  248. 'background-color' : '#EEE',
  249. 'padding' : '3px',
  250. 'margin' : '3px',
  251. });
  252.  
  253.  
  254. // can I touch _$('body.WebWizRTEtextarea')???