Recall?SKU Cleanup Helper

Helps in inputting text values into specified text fields using "Control+B" on pages with "Manhattan" in their title, with dynamic value count for ITEM_CBO.ITEM_NAME or LPN.TC_LPN_ID.

  1. // ==UserScript==
  2. // @name Recall?SKU Cleanup Helper
  3. // @version 0.6
  4. // @description Helps in inputting text values into specified text fields using "Control+B" on pages with "Manhattan" in their title, with dynamic value count for ITEM_CBO.ITEM_NAME or LPN.TC_LPN_ID.
  5. // @author You
  6. // @match *://*/*
  7. // @grant none
  8. // @namespace https://greasyfork.org/users/1183167
  9. // ==/UserScript==
  10. (function() {
  11. 'use strict';
  12.  
  13. console.log("Script loaded");
  14.  
  15. if (!document.title.includes("Manhattan")) {
  16. console.log("Page title does not include 'Manhattan'. Exiting script.");
  17. return;
  18. }
  19.  
  20. console.log("Page title includes 'Manhattan'. Script active without mode check and DOM observation.");
  21.  
  22. function findSelectorsWithSpecificOption(value) {
  23. const allSelectElements = document.querySelectorAll('select[id*="ruleSelDtlDataTable"][id*="ruleSelDtlColumnList"]');
  24. return Array.from(allSelectElements).filter(select =>
  25. select.querySelector(`option[value="${value}"][selected="selected"]`)
  26. ).map(select => parseInt(select.id.match(/(\d+)/)[1], 10)).sort((a, b) => a - b);
  27. }
  28.  
  29. document.addEventListener('keydown', function(e) {
  30. if (e.ctrlKey && e.key === 'b') {
  31. console.log("Detected 'Control+B' keypress.");
  32. const lpnIndices = findSelectorsWithSpecificOption('LPN.TC_LPN_ID');
  33. const itemCboIndices = findSelectorsWithSpecificOption('ITEM_CBO.ITEM_NAME');
  34.  
  35. let targetIndices, valueLabel;
  36. if (lpnIndices.length > 0) {
  37. targetIndices = lpnIndices;
  38. valueLabel = 'LPN.TC_LPN_ID';
  39. } else if (itemCboIndices.length > 0) {
  40. targetIndices = itemCboIndices;
  41. valueLabel = 'ITEM_CBO.ITEM_NAME';
  42. } else {
  43. console.log("No matching selectors found for either value. Ignoring 'Control+B' keypress.");
  44. return;
  45. }
  46.  
  47. const count = targetIndices.length;
  48. let inputString = prompt(`Enter up to ${count} value(s) separated by spaces for ${valueLabel}:`);
  49. if (inputString) {
  50. let values = inputString.split(/\s+/);
  51. if (values.length > count) {
  52. alert(`You entered more values than the acceptable limit of ${count}. Please try again.`);
  53. return; // Prevent execution if too many values are provided
  54. }
  55. applyValues(values, targetIndices); // Pass 'count' to ensure all fields are considered
  56. }
  57. }
  58. });
  59.  
  60. function applyValues(values, matchingIndices) {
  61. matchingIndices.forEach((index, i) => {
  62. const selector = `#dataForm\\:ruleSelDtlDataTable\\:${index}\\:ruleSelDtlRuleCmparValue`;
  63. let inputField = document.querySelector(selector);
  64. if (inputField) {
  65. // Update with provided value or "UPDATE" if out of user-provided values
  66. inputField.value = i < values.length ? values[i] : "UPDATE";
  67. console.log(`Updated field ${selector} with value: ${inputField.value}`);
  68. inputField.dispatchEvent(new Event('change', { 'bubbles': true }));
  69. }
  70. });
  71. }
  72. })();