SGW Item Modification Helper

Improves the modification page

当前为 2018-01-11 提交的版本,查看 最新版本

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