preload.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. window.busying = false
  2. // 处理 AngularJS 集成
  3. function handleAngularJS(select) {
  4. try {
  5. const scope = angular.element(select).scope();
  6. if (scope && scope.$apply) {
  7. scope.$apply(function() {
  8. // 确保 AngularJS 知道变化
  9. const modelName = select.getAttribute('ng-model');
  10. if (modelName) {
  11. scope[modelName] = select.value;
  12. }
  13. });
  14. }
  15. } catch (error) {
  16. console.log('AngularJS 处理失败(可忽略):', error);
  17. }
  18. }
  19. function triggerChangeEvents(select) {
  20. const events = ['input', 'change', 'blur'];
  21. events.forEach(eventType => {
  22. const event = new Event(eventType, { bubbles: true });
  23. select.dispatchEvent(event);
  24. });
  25. }
  26. function selectThirdOrString3(selectorStr) {
  27. const select = document.querySelector('.selectpicker');
  28. if (!select) return false;
  29. // 首先尝试选择值为 "string:3號" 的选项
  30. for (let i = 0; i < select.options.length; i++) {
  31. if (select.options[i].value.includes(selectorStr)) {
  32. select.selectedIndex = i;
  33. triggerChangeEvents(select);
  34. handleAngularJS(select);
  35. console.log('已选择: ' + selectorStr);
  36. return true;
  37. }
  38. }
  39. console.log('未找到匹配的选项');
  40. return false;
  41. }
  42. setInterval(() => {
  43. if (!window.busying) {
  44. if (location.href.includes('https://www.goopi.co/products/')) {
  45. document.title = '运行中!'
  46. // 先判断 货号
  47. selectThirdOrString3('string:3號');
  48. if (document.querySelector('#btn-main-checkout')) {
  49. window.busying = true
  50. document.title = '跳转中!'
  51. setTimeout(() => {
  52. location.href="https://www.goopi.co/checkout"
  53. }, 1000);
  54. }
  55. if (document.querySelector('[ng-if="!isItemInBackInStock"]')) {
  56. window.busying = true
  57. setTimeout(() => {
  58. window.busying = false
  59. location.reload()
  60. }, 3000);
  61. }
  62. }
  63. if (location.href.includes('https://www.goopi.co/cart')) {
  64. document.title = '结账中!'
  65. window.busying = true
  66. if (document.querySelector('.btn-checkout')) {
  67. document.querySelector('.btn-checkout').click()
  68. }
  69. }
  70. }
  71. }, 1000);