// ==UserScript== // @name OMG開單-樂(URL 參數版) // @namespace http://tampermonkey.net/ // @version 4.0 // @description try to take over the world! // @author 紫 // @include https://trade.omg.com.tw/Product/SellAdd* // @icon https://www.google.com/s2/favicons?domain=funpoint.com.tw // @grant none // ==/UserScript== (function() { 'use strict'; window.alert = function(){return !0;}; let s=document.getElementById("GameID"); s.selectedIndex = 2 + Math.floor(Math.random() * 10); s.dispatchEvent(new Event('change')); // document.getElementById("GameID").style.display = "none"; document.getElementById("ProductType").style.display = "none"; document.getElementById("ProductDesc").style.display = "none"; document.getElementById("StartDate").style.display = "none"; document.getElementById("EndDate").style.display = "none"; document.querySelector('footer.lineat').style.display = 'none'; // 頁面載入後立即執行 $(document).ready(function() { // 建立一個 URLSearchParams 物件來輕鬆讀取 URL 參數 const urlParams = new URLSearchParams(window.location.search); // 讀取 'itemId' 和 'quantity' 參數 const itemId = urlParams.get('itemId'); const quantity = urlParams.get('quantity'); // 先取得要操作的顯示元素 const displayElement = document.getElementsByClassName('CM-text-sec CM-fz-s')[4]; // --- 【關鍵邏輯修改】 --- // 第一層:只檢查 itemId 是否存在 if (itemId) { // 如果 itemId 存在,不論 quantity 如何,都先執行這些 console.log(`從 URL 成功讀取資料: ItemID=${itemId}`); jQuery("#ProductName").val(itemId); jQuery("#GamePlayerName").val(itemId); // 這些欄位似乎與 quantity 無關,所以也一併填寫 jQuery("#Counts").val('9'); jQuery("#ProductDesc").val('交易序號VHUCILKS5MN' + Math.floor(Math.random() * 10000000)); // 第二層:在 itemId 存在的基礎上,再處理 quantity if (quantity) { // 如果 quantity 也存在,則處理 Price 和除法邏輯 console.log(`同時讀取到 Quantity: ${quantity}`); const quantityNum = parseInt(quantity, 10); if (!isNaN(quantityNum) && quantityNum % 4 === 0) { // 可以被 4 整除 jQuery("#Price").val(quantity); // 填寫正確的價格 displayElement.innerText = quantityNum / 4; displayElement.style.color = ''; displayElement.style.fontWeight = ''; } else { // 不能被 4 整除 jQuery("#Price").val(''); // 清空價格 displayElement.innerText = '無法整除!!'; displayElement.style.color = 'red'; displayElement.style.fontWeight = 'bold'; } } else { // 如果 itemId 存在,但 quantity 不存在 console.log("URL 中僅找到 itemId,未找到 quantity。"); jQuery("#Price").val(''); // 價格欄位留空 displayElement.innerText = ''; // 清空顯示區域 displayElement.style.color = ''; displayElement.style.fontWeight = ''; } } else { // 如果連 itemId 都沒有,才使用完全預設的值 console.log("URL 中未找到資料,使用預設值。"); jQuery("#ProductName").val('999A'); jQuery("#GamePlayerName").val('999A'); jQuery("#Price").val(''); jQuery("#ProductDesc").val('交易序號VHUCILKS5MN' + Math.floor(Math.random() * 10000000)); jQuery("#Counts").val('9'); if(displayElement) { displayElement.innerText = ''; displayElement.style.color = ''; displayElement.style.fontWeight = ''; } } }); })();