SGW Item Modification Helper

Improves the modification page

目前为 2017-12-28 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name SGW Item Modification Helper
  3. // @namespace greasyfork.org
  4. // @version 1.3.2
  5. // @grant none
  6. // @require https://greasyfork.org/scripts/23449-gm-api-script/code/GM%20API%20script.js?upDate=2016_09_23
  7. // @include https://sellers.shopgoodwill.com/sellers/modifyItem.asp*
  8. // @description Improves the modification page
  9. // ==/UserScript==
  10.  
  11. $('*[name]').not('[id]').each(function(){
  12. $(this).attr('id', $(this).attr('name'));
  13. });
  14.  
  15.  
  16.  
  17. $('#itemTitle').parent().parent().parent().hide();
  18. $('#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>");
  19.  
  20. $('#contentTD').append("<p id='itemTitleContainer'><b>Item Title:</b> </p>");
  21. $('#itemTitleContainer').append($('#itemTitle'));
  22.  
  23. $('#contentTD').append("<p id='itemCategoryContainer'><b>Category:</b> </p>");
  24. $('#itemCategoryContainer').append($('#s1'));
  25.  
  26. $('#contentTD').append("<p id='itemDescriptionContainer'><b>Description:</b> </p>");
  27. $('#itemDescriptionContainer').append($('#colourPalette').parent());
  28.  
  29. // TODO: Shipping calculator?
  30. $('#contentTD').append("<div id='itemShippingDetailsContainer'></div>");
  31. $('#itemShippingDetailsContainer').append("<p id='itemShippingWeightContainer'><b>Shipping Weight:</b> </p>");
  32. $('#itemShippingWeightContainer').append($('#itemWeight'));
  33. $('#itemShippingDetailsContainer').append("<p id='itemDisplayWeightContainer'><b>Display (Actual) Weight:</b> </p>");
  34. $('#itemDisplayWeightContainer').append($('#itemDisplayWeight'));
  35. $('#itemShippingDetailsContainer').append("<p id='itemShippingPriceContainer'><b>Shipping Charge:</b><br></p>");
  36. $('#itemShippingPriceContainer').append($('#itemShippingPrice'));
  37. $('#itemShippingDetailsContainer').append("<p id='itemShipMethodContainer'><b>Shipping Method:</b> <br></p>");
  38. $('#itemShipMethodContainer').append($('#itemShipMethod'));
  39. $('#itemShippingDetailsContainer').append("<p id='itemNoCombineShippingContainer'><b>Item Shipment Combining:</b><br></p>");
  40. $('#itemNoCombineShippingContainer').append($('#itemNoCombineShipping'));
  41. $('#itemNoCombineShippingContainer').append(" Select this option if the buyer of this item should not be allowed to combine this item with shipment of other items.");
  42. $('#itemShippingDetailsContainer').append("<p id='itemAutoInsuranceContainer'><b>Auto Include Insurance (USPS Only):</b></p>");
  43. $('#itemAutoInsuranceContainer').append($('#itemAutoInsurance'));
  44.  
  45. $('#contentTD').append("<p id='itemsellerstoreContainer'><b>Seller Store:</b> </p>");
  46. $('#itemsellerstoreContainer').append($('#itemsellerstore'));
  47.  
  48. $('#itemSellerInventoryLocationID').parent().attr('id', 'itemSellerInventoryLocationIDContainer').appendTo($('#contentTD'));
  49.  
  50. $('#contentTD').append("<p id='itemSellerInfoContainer'><b>Seller Private Description:</b><br></p>");
  51. $('#itemSellerInfoContainer').append($('#itemSellerInfo'));
  52.  
  53. $('#contentTD').append("<p style='position:relative; left: 10px; padding-bottom:4px;'><span class='fakeButton' onclick='$(\"#hiddenJunk\").toggle();'>Show/hide hidden fields/etc.</span></p>");
  54.  
  55.  
  56. $('#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>");
  57.  
  58. $('#hiddenJunkTD').append("<p id='itemQuantityContainer'><b>Item Quantity: </b></p>");
  59. $('#itemQuantityContainer').append($('#itemQuantity').parent());
  60.  
  61. $('#hiddenJunkTD').append("<p id='itemMinimumBidContainer'><b>Minimum Bid: </b></p>");
  62. $('#itemMinimumBidContainer').append($('#itemMinimumBid').parent());
  63.  
  64. $('#hiddenJunkTD').append("<p id='itemBidIncrementContainer'><b>Bid Increment: </b></p>");
  65. $('#itemBidIncrementContainer').append($('#itemBidIncrement').parent());
  66.  
  67. $('#hiddenJunkTD').append("<p id='itemReserveContainer'><b>Reserve Price: </b></p>");
  68. $('#itemReserveContainer').append($('#itemReserve').parent());
  69. $('#itemReserve').parent().children().first().remove();
  70.  
  71. $('#hiddenJunkTD').append("<p id='itemBuyNowPriceContainer'><b>Buy Now Price: </b></p>");
  72. $('#itemBuyNowPriceContainer').append($('#itemBuyNowPrice').parent());
  73. $('#itemBuyNowPrice').parent().children().first().remove();
  74.  
  75. $('#hiddenJunkTD').append("<p id='itemActualDimensionsContainer'></p>");
  76. $('#itemActualDimensionsContainer').append($('#itemLength').parent().parent().parent());
  77.  
  78. $('#hiddenJunkTD').append("<p id='itemShippingDimensionsContainer'></p>");
  79. $('#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>');
  80. $('#itemShippingDimensionsContainer').append($('#itemShipLength'));
  81. $('#itemShippingDimensionsContainer').append(" <font face='Arial' size='2'>(Numbers and decimal point '.' only) Used for shipping optimization and prevention of oversized charges.</font>");
  82.  
  83. $('#hiddenJunkTD').append("<p id='itemShippingContainer'><b>Shipping: </b><p>");
  84. $('#itemShippingContainer').append($('#itemShipping'));
  85. $('#itemShippingContainer').append($('select[name="itemShipping"]'));
  86.  
  87. $('#hiddenJunkTD').append("<p id='itemHandlingPriceContainer'><b>Handling Charge: </b></p>");
  88.  
  89. $('#itemHandlingPriceContainer').append($('#itemHandlingPrice').parent());
  90. $('#itemHandlingPrice').parent().children().first().remove();
  91.  
  92. $('#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>");
  93.  
  94. $('#itemShipMethod option[value="3"]').text('Post Office');
  95.  
  96.  
  97. $('#itemTitleContainer').after('<div id="counterContainer"><font face="Arial" size="4">You have <b><span id="myCounter"></span></b> characters remaining.</font></div>');
  98. $("#myCounter").html(50-$('#itemTitle').val().length);
  99. $('#itemTitle').bind('keyup', function(){
  100. $("#myCounter").html(50-$('#itemTitle').val().length);
  101. });
  102.  
  103. // --------- Shipping calculator --------------------------------------------
  104.  
  105. if ($('#shipCalcContainer').length > 0) {
  106. // Doesn't do these things if the user doesn't have the new shipping calculator script installed.
  107.  
  108. // $("#itemSellerInfo").after("<b>Note to shipping:</b><br><textarea id='noteToShipping' rows='2' cols='40'></textarea><br>");
  109. // $('#itemSellerInfo').hide();
  110. $("b:contains('Shipping Charge')").before($('.shippingOptions').first());
  111. $('.shippingOptions').eq(1).remove();
  112. // I have NO IDEA why the shippingOptions div gets duplicated, rather than just moved!
  113. $('#itemDescriptionContainer').after($('#shipCalcContainer').css({'margin-top' : '15px', 'margin-bottom' : '20px'}));
  114.  
  115. var sgwTimeouts = window.setTimeout(function(){
  116.  
  117. // $('#myCounter').bind('change', function(){
  118. // var len49 = Math.ceil($('#myCounter').html());
  119. // $('#myCounter2').html(len49 + 1);
  120. // })
  121.  
  122. function dummyWeight() {
  123. if ($('#itemWeight').val().length < 1) {
  124. $('#itemWeight').val(1);
  125. }
  126. if ($('#itemDisplayWeight').val().length < 1) {
  127. $('#itemDisplayWeight').val(1);
  128. }
  129. }
  130. // disabling this due to conflicts
  131. /*
  132. $('#submit1').bind('click', function(e){
  133. e.preventDefault();
  134. var submitForm = true;
  135. while ($('#itemTitle').val().length < 1) {
  136. $('#itemTitle').val(prompt('Item title?'));
  137. }
  138. if ($('#itemWeight').val().length < 1) {
  139. if ($('#currentShipCalcType').val() == 'USPS') {
  140. while ($('#itemWeight').val().length < 1) {
  141. var weight = prompt("Item's weight?");
  142. $('#itemWeight').val(weight);
  143. $('#itemDisplayWeight').val(weight);
  144. }
  145. } else if ($('#currentShipCalcType').val() == 'pickup') {
  146. $('#itemWeight').val(150);
  147. } else {
  148. alert('Please enter shipping information!');
  149. $('.calcInput:empty').first().focus();
  150. submitForm = false;
  151. }
  152. }
  153. while ($('#itemDisplayWeight').val().length < 1) {
  154. $('#itemDisplayWeight').val(prompt('Item\'s actual weight?'));
  155. }
  156. if ($('#itemDescription').val().length < 1) {
  157. // alert('Please enter a description!');
  158. // submitForm = false;
  159. // Doesn't work. Huh.
  160. }
  161. if (submitForm === true) {
  162. if ($('#itemsellerstore').val() == '999') {
  163. $('#itemsellerstore').val('999 - Mixed Locations');
  164. }
  165. var shipString = '<<';
  166. if ($('#Clothing').css('background-color') == 'rgb(170, 170, 170)') {
  167. shipString += 'clth:'+$('#actualWeight').val()+'#';
  168. if ($('#itemShipMethod').val() == 2) {
  169. shipString += '/' + $('#dim1').val() + 'x' + $('#dim2').val() + 'x' + $('#dim3').val();
  170. }
  171. } else if ($('#Media').css('background-color') == 'rgb(170, 170, 170)') {
  172. shipString += 'mdia+'+$('#actualWeight').val()+'#';
  173. } else {
  174. if ($('#currentShipCalcType').val() == 'general') {
  175. shipString += 'gen:';
  176. } else if ($('#currentShipCalcType').val() == 'guitar') {
  177. shipString += 'guit:';
  178. } else if ($('#currentShipCalcType').val() == 'art') {
  179. shipString += 'art:';
  180. } else if ($('#currentShipCalcType').val() == 'long') {
  181. shipString += 'long:';
  182. }
  183. if ($('#dim1').val().length > 0 && $('#dim2').val().length > 0 && $('#dim3').val().length > 0) {
  184. shipString += $('#actualWeight').val() + '#/' + $('#dim1').val() + 'x' + $('#dim2').val() + 'x' + $('#dim3').val();
  185. }
  186. }
  187. shipString += '>>';
  188. console.log(shipString);
  189. $('#itemSellerInfo').val($('#itemSellerInfo').val()+shipString);
  190. if ($('#noteToShipping').val().length > 0) {
  191. $('#itemSellerInfo').val($('#itemSellerInfo').val()+'<br><br><b>Note from ' + $('#posterName').html() + ': </b>' + $('#noteToShipping').val());
  192. }
  193. $('#form1').submit();
  194. }
  195. });
  196. */
  197. function validateCombineCat(cat) {
  198. noCombine = ['Sculpture', 'Figurine', 'Cookie Jar', 'Music Box', 'Glass', 'Grabbag', 'Barware', 'China', 'Cookware', 'Serving Piece', 'Wedding Dress', 'Gown',];
  199. combine = true;
  200. // $.each()
  201. // I don't think I want it to automatically do this.
  202. }
  203.  
  204. $('.upsButton').bind('click', function(){
  205. useSuggestion('UPS');
  206. });
  207. $('.uspsButton').bind('click', function(){
  208. useSuggestion('USPS');
  209. });
  210. $('.pickupOnlyButton').bind('click', function(){
  211. useSuggestion('pickup');
  212. });
  213.  
  214. function buttonClickAnimate(button) {
  215. button.css('background-color', '#AAA').animate({
  216. 'background-color' : '#EEE',
  217. }, 500);
  218. }
  219.  
  220. function weightPrompt() {
  221. var displayWeight = Math.ceil($('#addPounds').html());
  222. while ($('#actualWeight').val().length < 1) {
  223. var actualWeight = prompt('Item\'s actual weight?');
  224. actualWeight = actualWeight.replace(/[^\d.-]/g,'');
  225. $('#actualWeight').val(actualWeight);
  226. displayWeight += Math.ceil(actualWeight);
  227. $('#calc-'+$('#currentShipCalcType').val()).trigger("click");
  228. }
  229.  
  230. $('#itemDisplayWeight').val(displayWeight);
  231. }
  232.  
  233. $('#calc-media').bind('click', function(){
  234. buttonClickAnimate($(this));
  235. $('#Media') .trigger('click');
  236. });
  237.  
  238. $('#calc-clothing').bind('click', function(){
  239. buttonClickAnimate($(this));
  240. weightPrompt();
  241. var weight = parseFloat($('#actualWeight').val());
  242. $('#itemDisplayWeight').val(weight);
  243. calculateUSPS(weight);
  244. });
  245.  
  246. $('.shipCharge').bind('click', function(){
  247. $('.shipType').css('background-color', '#EEE');
  248. $(this).css('background-color', '#AAA');
  249. var thisBox = $(this).text();
  250. var boxData = $('#boxDefinitions').data()[thisBox];
  251. weightPrompt();
  252. if (thisBox == 'Media') {
  253. doMedia($('#actualWeight').val());
  254.  
  255. } else if (thisBox == 'Clothing' || thisBox == 'Small&light') {
  256. $('#calc-clothing').trigger('click');
  257. } else if (boxData['method'] == 'USPS') {
  258. $('#itemDisplayWeight').val($('#actualWeight').val());
  259. $('#itemWeight').val($('#actualWeight').val());
  260. $('#itemShippingPrice').val(boxData['price']);
  261. $('#shipTypeNote').val(thisBox);
  262. } else if (boxData['method'] == 'UPS') {
  263. $('#itemDisplayWeight').val($('#actualWeight').val());
  264. realWeight = Math.ceil($('#actualWeight').val())+Math.ceil($('#addInches').html());
  265. if (realWeight > boxData['weight']) {
  266. $('#itemWeight').val(realWeight);
  267. } else {
  268. $('#itemWeight').val(boxData['weight']);
  269. }
  270. $('#shipTypeNote').val(boxData['note']);
  271. }
  272. if (boxData['method'].length > 0) {
  273. // console.log('.shipCharge():'+boxData['method']);
  274. shippingMethod(boxData['method']);
  275. }
  276. });
  277.  
  278. function useSuggestion(type) {
  279. buttonClickAnimate($('.'+type+'Button:visible'));
  280. if (type == 'pickupOnly') {
  281. type = 'pickup';
  282. }
  283. // console.log('useSuggestion():'+type);
  284. shippingMethod(type);
  285. weightPrompt();
  286. $('#itemDisplayWeight').val($('#actualWeight').val());
  287. if (type == 'UPS') {
  288. $('#itemWeight').val($('#shipCalcShippingWeight').html());
  289. } else if (type == 'USPS') {
  290. $('#itemWeight').val($('#actualWeight').val());
  291. $('#itemShippingPrice').val($('#uspsSuggPrice').html());
  292. } else if (type == 'pickup') {
  293. $('#itemWeight').val(150);
  294. }
  295. }
  296.  
  297. $('#UPS').bind('click', function(){
  298. weightPrompt();
  299. dimList = [$('#dim1').val(), $('#dim2').val(), $('#dim3').val()];
  300. $.each(dimList, function(index, dim){
  301. index+=1;
  302. while (dim.length < 1) {
  303. dim = prompt('Dimension ' + index);
  304. $('#dim'+index).val(dim);
  305. }
  306. });
  307. $('#calc-'+$('#currentShipCalcType').val()).trigger('click');
  308. if($('.upsButton:visible').length > 0) {
  309. useSuggestion('UPS');
  310. } else {
  311. useSuggestion('pickup');
  312. }
  313. });
  314.  
  315. $('#pickupOnly').bind('click', function(){
  316. weightPrompt();
  317. shippingMethod('pickup');
  318. });
  319.  
  320. function shippingMethod(method) {
  321. // console.log('shippingMethod() '+method);
  322. $('#UPS, #pickup').css('background-color', '#EEE');
  323. $('#itemShipMethod > option').removeAttr('selected');
  324. if (method == 'UPS') {
  325. $('#itemShipMethod').val(2);
  326. $('#itemAutoInsurance').removeProp('checked');
  327. $('#itemShippingPrice').val(0);
  328. $('#UPS').css('background-color', '#AAA');
  329. } else if (method =='pickup') {
  330. // console.log('a');
  331. $('#itemShipMethod').val(0);
  332. $('#itemAutoInsurance').removeProp('checked');
  333. $('#itemShippingPrice').val(0);
  334. $('#itemWeight').val(150);
  335. $('#pickupOnly').css('background-color', '#AAA');
  336. } else if (method == 'USPS') {
  337. // console.log('???');
  338. $('#itemShipMethod').val(3);
  339. $('#itemAutoInsurance').prop('checked', true);
  340. $('#itemWeight').val(Math.ceil($('#actualWeight').val()) + Math.ceil($('#addPounds').html()));
  341. }
  342. }
  343.  
  344. function getCharge(myWeight) {
  345. console.log('getCharge:'+myWeight);
  346. if (myWeight <= 3) {
  347. return '3.99';
  348. } else if (myWeight <= 6) {
  349. return '5.99';
  350. } else if (myWeight <= 10) {
  351. return '7.99';
  352. } else if (myWeight <= 13) {
  353. return '8.99';
  354. } else if (myWeight <= 15) {
  355. return '9.99';
  356. } else if (myWeight <= 19) {
  357. return '11.99';
  358. } else if (myWeight <= 25) {
  359. return '15.99';
  360. } else if (myWeight <= 27) {
  361. return '16.99';
  362. } else if (myWeight <= 29) {
  363. return '17.99';
  364. } else if (myWeight <= 31) {
  365. return '18.99';
  366. } else if (myWeight <= 33) {
  367. return '19.99';
  368. } else if (myWeight <= 35) {
  369. return '20.99';
  370. } else if (myWeight <= 37) {
  371. return '21.99';
  372. } else if (myWeight <= 39) {
  373. return '22.99';
  374. } else if (myWeight <= 41) {
  375. return '23.99';
  376. } else if (myWeight <= 43) {
  377. return '24.99';
  378. } else if (myWeight <= 45) {
  379. return '25.99';
  380. } else if (myWeight <= 47) {
  381. return '26.99';
  382. } else if (myWeight <= 49) {
  383. return '27.99';
  384. } else if (myWeight <= 51) {
  385. return '28.99';
  386. } else if (myWeight <= 53) {
  387. return '29.99';
  388. } else if (myWeight <= 55) {
  389. return '30.99';
  390. } else if (myWeight <= 57) {
  391. return '31.99';
  392. } else if (myWeight <= 59) {
  393. return '32.99';
  394. } else if (myWeight <= 61) {
  395. return '33.99';
  396. } else if (myWeight <= 63) {
  397. return '34.99';
  398. } else if (myWeight <= 65) {
  399. return '35.99';
  400. } else if (myWeight <= 67) {
  401. return '36.99';
  402. } else if (myWeight <= 68) {
  403. return '37.99';
  404. } else if (myWeight <= 69) {
  405. return '38.99';
  406. } else if (myWeight <= 70) {
  407. return '39.99';
  408. }
  409. }
  410. function doMedia(weight) {
  411. console.log('media:'+weight);
  412. var myCharge;
  413. if (weight < 50) {
  414. myCharge = getCharge(weight);
  415. } else if (weight < 70) {
  416. myCharge = 2 * getCharge(weight/2);
  417. } else {
  418. if (weight <= 140) {
  419. weight /= 2;
  420. myCharge = 2.25 * getCharge(weight);
  421. } else if (weight <= 210) {
  422. weight /= 3;
  423. myCharge = 3.5 * getCharge(weight);
  424. }
  425. myCharge = (Math.ceil(myCharge) - .01)
  426. }
  427.  
  428. $('#itemDisplayWeight').val(weight);
  429. $('#itemWeight').val(weight);
  430. $('#itemShippingPrice').val(myCharge);
  431. $('#shipTypeNote').val('Media');
  432. shippingMethod('USPS');
  433. }
  434. }, 1100);
  435.  
  436. }
  437.  
  438. $('.fakeButton').css({
  439. 'border' : '1px solid #CCC',
  440. 'background-color' : '#EEE',
  441. 'padding' : '3px',
  442. 'margin' : '3px',
  443. });
  444.  
  445. // don't forget checkboxes! also #table does not have a val()...
  446.  
  447. // can I touch $('body.WebWizRTEtextarea')???