// ==UserScript==
// @name ACGN-stock營利統計外掛
// @namespace http://tampermonkey.net/
// @version 2.900
// @description try to take over the world!
// @author SoftwareSing
// @match http://acgn-stock.com/*
// @match https://acgn-stock.com/*
// @grant none
// ==/UserScript==
//版本號為'主要版本號 + "." + 次要版本號 + 錯誤修正版本號(兩位),ex 1.801
//修復導致功能失效的錯誤或更新重大功能提升主要或次要版本號
//優化UI,優化效能,優化小錯誤更新錯誤版本號
//兩個錯誤修正版本號防止迫不得已進位到次要版本號
//本腳本修改自 "ACGN股票系統每股營利外掛 2.200 by papago89"
var wasCompany, wasStockSummary, wasaccountInfo, wasfoundationPlan, oldUrl;
// 程式進入點
(function mainfunction() {
//最高優先
checkSeriousError();
setTimeout(checkScriptEvent, 500);
//設定狀態
wasCompany = (document.location.href.search(/company\/detail/) != -1);
wasStockSummary = (document.location.href.search(/company\/[0-9]+/) != -1);
wasAccountInfo = (document.location.href.search(/accountInfo/) != -1);
wasFoundationPlan = document.location.href.search(/foundation/) != -1;
oldUrl = document.location.href;
//針對現在的頁面做反應
if(wasCompany)
setTimeout(addCompanyEvent, 1000);
else if(wasStockSummary)
setTimeout(addSSEvent, 1000); // StockSummary
else if(wasAccountInfo)
setTimeout(addAIEvent, 1000); // AccountInfo
else if(wasFoundationPlan)
setTimeout(addFPEvent, 1000); // FoundationPlan
//全域事件
setTimeout(checkDividendUpdateTime, 1000);
setTimeout(addEvent, 5000);
setTimeout(addAD, 3900);
})();
function addCompanyEvent()
{
//公司細節頁面
setTimeout(addCompanyClickListener, 1000);
}
function addAIEvent()
{
//帳號資訊頁面
setTimeout(addManagerSalaryInfo, 1500);
setTimeout(callAddUserProfitInfo, 2500);
}
function addSSEvent()
{
//公司總覽頁面
setTimeout(addStockSummaryListener, 1000);
}
function addFPEvent()
{
//新創公司頁面
}
// 監測main的變化並判斷當前屬於哪個頁面加入正確的事件監聽
function addEvent()
{
$('#main').bind("DOMNodeInserted DOMNodeRemoved", function(){
// 因AJAX動態生成不斷執行,所以有時候main的變動並不代表換頁,此時無須重新加入事件
if(oldUrl != document.location.href && document.location.href.search(/company\/detail/) != -1)
setTimeout(addCompanyEvent, 1000);
else if(oldUrl != document.location.href && document.location.href.search(/company\/[0-9]+/) != -1)
setTimeout(addSSEvent, 1000);
else if(oldUrl != document.location.href && document.location.href.search(/accountInfo/) != -1)
setTimeout(addAIEvent, 1000);
else if(oldUrl != document.location.href && document.location.href.search(/foundation/) != -1)
setTimeout(addFPEvent, 1000);
wasCompany = (document.location.href.search(/company\/detail/) != -1);
wasStockSummary = (document.location.href.search(/company\/[0-9]+/) != -1);
wasAccountInfo = (document.location.href.search(/accountInfo/) != -1);
wasFoundationPlan = document.location.href.search(/foundation/) != -1;
oldUrl = document.location.href;
});
}
function checkSeriousError()
{
//這個function將會清空所有由本插件控制的localStorage
//用於如果上一版發生嚴重錯誤導致localStorage錯亂,以致插件無法正常啟動時
//或是用於當插件更新時,需要重設localStorage
var seriousErrorVersion = 2.700;
//seriousErrorVersion會輸入有問題的版本號,當發生問題時我會增加本數字,或是於更新需要時亦會增加
//使用者本地的數字紀錄如果小於這個數字將會清空所有localStorage
var lastErrorVersion = 0 !== window.localStorage.getItem ("lastErrorVersion") ? Number(JSON.parse(window.localStorage.getItem ("lastErrorVersion"))) : 0;
//lastErrorVersion = 0; //你如果覺得現在就有問題 可以把這行的註解取消掉來清空localStorage
console.log(Number.isInteger(lastErrorVersion));
console.log(lastErrorVersion);
if (Number.isNaN(lastErrorVersion))
{
lastErrorVersion = 0;
console.log("reset lastErrorVersion as 0");
}
else
{
console.log("localStorage of lastErrorVersion is work");
}
if (lastErrorVersion < seriousErrorVersion)
{
console.log("last version has serious error, start remove all localStorage");
window.localStorage.removeItem ("Dividend_UpdateTime");
window.localStorage.removeItem ("Dividend");
window.localStorage.removeItem ("lastErrorVersion");
lastErrorVersion = seriousErrorVersion;
window.localStorage.setItem ("lastErrorVersion", JSON.stringify(lastErrorVersion));
}
}
function get_other_JsonObj(jsonLink)
{
var request = new XMLHttpRequest();
request.open("GET", jsonLink, false); // 連線 POST到該連線位址
request.send();
other_jsonObj = JSON.parse(request.responseText);
}
function get_abcd1357_JsonObj()
{
var request = new XMLHttpRequest();
request.open("GET", "https://jsonbin.org/abcd1357/ACGNstock-company", false); // 連線 POST到該連線位址
request.send();
abcd1357_jsonObj = JSON.parse(request.responseText);
}
function checkDividendUpdateTime()
{
get_abcd1357_JsonObj();
//window.localStorage.removeItem ("Dividend_UpdateTime");
var Dividend_UpdateTime = null !== window.localStorage.getItem ("Dividend_UpdateTime") ? JSON.parse(window.localStorage.getItem ("Dividend_UpdateTime")) : "null";
if (abcd1357_jsonObj.updateTime === Dividend_UpdateTime)
{
console.log("dont need update " + Dividend_UpdateTime);
}
else
{
console.log("server update time: " + abcd1357_jsonObj.updateTime);
console.log("local update time: " + Dividend_UpdateTime);
console.log("start update data");
updateDividendData();
}
}
function updateDividendData()
{
get_abcd1357_JsonObj();
var Dividends = [];
//console.log(abcd1357_jsonObj.companys[0].companyID);
//console.log(abcd1357_jsonObj.companys[0].companyDividend);
for (var n in abcd1357_jsonObj.companys)
{
Dividends.push({"companyID": String(abcd1357_jsonObj.companys[n].companyID),
"companyDividend": String(abcd1357_jsonObj.companys[n].companyDividend),
"companyPrice": String(abcd1357_jsonObj.companys[n].companyPrice),
"companyStock": String(abcd1357_jsonObj.companys[n].companyStock) });
//console.log("push success");
}
window.localStorage.setItem ("Dividend", JSON.stringify(Dividends));
if (abcd1357_jsonObj.updateTime === null || abcd1357_jsonObj.updateTime === undefined)
{
window.localStorage.setItem ("Dividend_UpdateTime", JSON.stringify("no data"));
}
else
{
window.localStorage.setItem ("Dividend_UpdateTime", JSON.stringify(abcd1357_jsonObj.updateTime));
}
console.log("Dividend Cookie Update Success!!");
}
/************UpdateScript*************/
function checkScriptEvent()
{
var myVersion = GM_info.script.version;
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", checkScriptVersion);
oReq.open("GET", "https://gf.qytechs.cn/scripts/33542.json");
oReq.send();
}
function checkScriptVersion()
{
var obj = JSON.parse(this.responseText);
var myVersion = GM_info.script.version;
console.log(obj.version.substr(0, 3) + "," + myVersion.substr(0, 3) + "," + (obj.version.substr(0, 3) > myVersion.substr(0, 3)));
if(obj.version.substr(0, 3) > myVersion.substr(0, 3))
$('<li class="nav-item"><a class="nav-link btn btn-primary" href="https://gf.qytechs.cn/zh-TW/scripts/33542" id="UpdateDividendScript" target="Blank">' + Dict[lan].updateDividendScript + '</a></li>').insertAfter($('.nav-item')[$('.nav-item').length - 1]);
else
setTimeout(checkScriptEvent, 600000);
}
/************UpdateScript*************/
/**************scriptAD***************/
function addAD()
{
console.log("start add script AD");
var data, adNumber, link, linkNumber = 0;
$('<a class="scriptAD float-left" id="scriptAD-0"> </a>').insertAfter($('.text-danger.float-left'));
get_AD_JsonObj();
var jsonData = AD_jsonObj;
console.log("ADnumber:" + jsonData.adFormat.length);
for (var adF = 0 ; adF < jsonData.adFormat.length ; ++adF)
{
console.log("adding AD");
adNumber = Number($('.scriptAD').length);
data = jsonData.adData[adF];
if (jsonData.adFormat[adF] == "a")
{
$('<a class="scriptAD float-left" id="scriptAD-' + adNumber + '">' + data + '</a>').insertAfter($('#scriptAD-' + (adNumber - 1)));
}
else if (jsonData.adFormat[adF] == "aLink")
{
link = jsonData.adLink[linkNumber];
$('<a class="scriptAD float-left" id="scriptAD-' + adNumber + '" href="' + link + '">' + data + '</a>').insertAfter($('#scriptAD-' + (adNumber - 1)));
linkNumber += 1;
}
}
/*
//$('<p class="scriptAD" id="scriptAD-1" Align="Center">支持工程猿創造更優質腳本<a class="scriptAD" id="scriptAD-2" href="/company/detail/TJjNe2Zqk3HyEbSdW">「壞掉妹」</a><a class="scriptAD" id="scriptAD-3" href="/company/detail/wWmCjLxt5HCfeahiX">「雪之下雪乃」</a><a class="scriptAD" id="scriptAD-4">懇請賜予推薦票</a></p>').insertAfter($('.text-danger.float-left'));
$('<a class="scriptAD float-left" id="scriptAD-1" Align="Center">★支持工程濕 創造更優質腳本★</a>').insertAfter($('.text-danger.float-left'));
$('<a class="scriptAD float-left" id="scriptAD-2" href="/company/detail/TJjNe2Zqk3HyEbSdW">「壞掉妹」</a>').insertAfter($('#scriptAD-1'));
$('<a class="scriptAD float-left" id="scriptAD-4">★懇請賜予推薦票★</a>').insertAfter($('#scriptAD-3'));
$('<a class="scriptAD float-left" id="scriptAD-0"> </a>').insertAfter($('.text-danger.float-left'));
*/
console.log("success add script AD");
}
function get_AD_JsonObj()
{
get_other_JsonObj("https://jsonbin.org/abcd1357/ACGNstock-AD");
AD_jsonObj = other_jsonObj;
}
/**************scriptAD***************/
/************stockSummary*************/
function addStockSummaryListener() {
setTimeout(computeProfit, 2100);
setTimeout(SSAddPEInfo, 2500);
/*$(".btn.btn-secondary.mr-1")[0].addEventListener("click", ComputeEvt);
$(".btn.btn-secondary.mr-1")[1].addEventListener("click", ComputeEvt);
var pagesbtn = $(".page-item");
for (var i = 0; i < pagesbtn.length; i++) {
pagesbtn[i].addEventListener("click", ComputeEvt);
}*/
console.log("Triggered StockSummary");
}
function ComputeEvt() {
setTimeout(addStockSummaryListener, 2000);
}
//總獲利計算--加入分紅計算
function computeProfit() {
//加入變數 profit為總獲利, ID是公司網址, earnPerShare是每股獲利
var profit = 0,
tag, price, hold, classProfit, ID, earnPerShare, index;
var Dividends = null !== window.localStorage.getItem ("Dividend") ? JSON.parse(window.localStorage.getItem ("Dividend")) : [];
//方格模式
if ($(".col-12.col-md-6.col-lg-4.col-xl-3").length > 0)
{
for (var i = 0; i < $('.company-card').length; ++i)
{
price = Number($('.company-card')[i].innerText.match(/\$ [0-9]+\(([0-9]+)\)/)[1]);
hold = Number($('.company-card')[i].innerText.match(/([0-9]+).+%.+/)[1]);
ID = $('.company-card')[i].innerHTML.match(/<a href="\/company\/detail\/([0-z]+)">/)[1];
console.log("companyID = " + ID);
index = Dividends.findIndex(x => x.companyID == ID);
if (index == -1)
{
earnPerShare = 0;
}
else
{
earnPerShare = Dividends[index].companyDividend;
profit += earnPerShare * hold;
}
//console.log("companyID = " + ID);
console.log("earnPerShare = " + earnPerShare);
console.log("");
}
console.log("本頁預計分紅: " + profit);
classProfit = $("#totalProfitNumber");
if (classProfit.length === 0)
{
$('<div class="media company-summary-item border-grid-body" id = "totalProfit"><div class="col-6 text-right border-grid" id = "totalProfitTitle"><h2>' + Dict[lan].totalProfitInThisPage + '</h2></div></div>').insertAfter($('.card-title.mb-1')[0]);
$('<div class="col-6 text-right border-grid" id = "totalProfitNumber"><h2>$ ' + profit.toFixed() + '</h2></div>').insertAfter($('#totalProfitTitle')[0]);
}
else
{
$("#totalProfitNumber")[0].innerHTML = "<h2>$ " + profit.toFixed() + "</h2>";
}
}
/*else
{ //列表模式
//列表模式暫不開放
//console.log($(".col-8.col-lg-3.text-right.border-grid"));
for (var j = 0; j < $('.media-body.row.border-grid-body').length; ++j) {
price = Number($('.media-body.row.border-grid-body')[j].innerText.match(/\$ [0-9]+\(([0-9]+)\)/)[1]);
hold = Number($('.media-body.row.border-grid-body')[j].innerText.match(/您在該公司持有([0-9]+)數量的股份/)[1]); // 找出持股量
console.log("價= " + price + ",持= " + hold + ",總= " + (price * hold) );
assets += price * hold;
}
console.log("本頁持股價值: " + assets);
classAssets = $("#totalAssetsNumber");
if (classAssets.length === 0) {
$('<div class="media company-summary-item border-grid-body" id = "totalAssets"><div class="col-6 text-right border-grid" id = "totalAssetsTitle"><h2>' + Dict[lan].totalAssetsInThisPage + '</h2></div></div>').insertAfter($('.card-title.mb-1')[0]);
$('<div class="col-6 text-right border-grid" id = "totalAssetsNumber"><h2>$ ' + assets + '</h2></div>').insertAfter($('#totalAssetsTitle')[0]);
} else {
$("#totalAssetsNumber")[0].innerHTML = "<h2>$ " + assets + "</h2>";
}
}*/
//setTimeout(computeAssets,1000);
}
function SSAddPEInfo(){
var price, hold, PE, ID, companyIndex;
var Dividends = null !== window.localStorage.getItem ("Dividend") ? JSON.parse(window.localStorage.getItem ("Dividend")) : [];
//方格模式
if($(".col-12.col-md-6.col-lg-4.col-xl-3").length > 0)
{
for(var i = 0; i < $('.company-card').length; ++i)
{
price = Number($('.company-card')[i].innerText.match(/\$ [0-9]+\(([0-9]+)\)/)[1]);
ID = $('.title a')[i].href.match(/\/company\/detail\/([^]+)/)[1];
companyIndex = Dividends.findIndex(c => c.companyID == ID);
if (companyIndex == -1)
{
PE = "?????";
}
else
{
if (Dividends[companyIndex].companyDividend === 0)
{
PE = "∞";
}
else
{
PE = price / (Dividends[companyIndex].companyDividend);
PE = PE.toFixed(3);
}
}
$('<div name="stockPEInfo" class="row row-info d-flex justify-content-between" id="stockPEInfo"><p>' + Dict[lan].stockPEInfo + '</p><p>' + PE + '</p></div>').insertAfter($('.company-card')[i].children[6]);
console.log("---" + ID + "---" + PE + "---");
}
}
//setTimeout(computeAssets, 1000);
}
/************stockSummary*************/
/*************************************/
/**************company****************/
//---------------按鍵區---------------//
function addCompanyClickListener() {
if ($('.d-block.h4').length === 6) {
// 初始化 先看使用者有沒有預設打開資料夾
folderOpenString = "fa-folder-open";
folderCloseString = "12345678";
//chartEvent();
numbersEvent();
//orderEvent();
//productEvent();
//directorEvent();
//logEvent();
folderOpenString = "fa-folder";
folderCloseString = "fa-folder-open";
// 註冊事件
//$('.d-block.h4')[0].addEventListener("click", chartEvent); //股價趨勢
$('.d-block.h4')[1].addEventListener("click", numbersEvent); //數據資訊
//$('.d-block.h4')[2].addEventListener("click", orderEvent); //交易訂單
//$('.d-block.h4')[3].addEventListener("click", productEvent); //產品中心
//$('.d-block.h4')[4].addEventListener("click", directorEvent); //董事會
//$('.d-block.h4')[5].addEventListener("click", logEvent); //所有紀錄
console.log("OnclickListener Registered");
} else {
setTimeout(addCompanyClickListener, 500);
}
console.log("Triggered Company");
}
var folderOpenString, folderCloseString;
// 數據資訊
function numbersEvent() {
var folderstate = $(".d-block.h4 i")[1].classList[1];
if (folderstate === folderOpenString) {
//Open Event
console.log("Open numbersfolder");
//setTimeout(addSomeInfo, 1000);
setTimeout(AddDividendCookie, 1000); //總獲利計算--紀錄分紅
} else if (folderstate === folderCloseString) {
//Close Event
console.log("close numbersfolder");
}
}
//總獲利計算--紀錄分紅cookie 09/27
//Dividends規格
//{"companyID": A, "companyDividend": B, "companyPrice": C, "companyStock": D}
function AddDividendCookie()
{
//window.localStorage.removeItem ("Dividend");
var revenue, totalStock, earnPerShare, ID, stockPrice;
stockPrice = Number($('.col-8.col-md-4.col-lg-2.text-right.border-grid')[0].innerHTML.match(/[0-9]+/));
revenue = $('.col-8.col-md-4.col-lg-2.text-right.border-grid')[3].innerHTML.match(/[0-9]+/);
totalStock = $('.col-8.col-md-4.col-lg-2.text-right.border-grid')[4].innerHTML.match(/[0-9]+/);
earnPerShare = 0.8075 * revenue / totalStock;
//name = $('.card-title.text-truncate')[0].innerText;
ID = document.location.href.substr(38,99);
var Dividends = null !== window.localStorage.getItem ("Dividend") ? JSON.parse(window.localStorage.getItem ("Dividend")) : [];
//如果先前紀錄過該公司,則刪除重記
var index = Dividends.findIndex(x => x.companyID == ID);
console.log(ID + "---" + earnPerShare + "---" + stockPrice);
if (index != -1)
{
if ((Dividends[index].companyDividend == earnPerShare) &&
(Dividends[index].companyPrice == stockPrice) &&
(Dividends[index].companyStock == totalStock))
{
console.log("dont need update cookie");
}
else
{
Dividends.splice(index, 1);
console.log("AddDividendCookie---splice");
Dividends.push({"companyID": ID, "companyDividend": earnPerShare, "companyPrice": stockPrice, "companyStock": totalStock});
window.localStorage.setItem ("Dividend", JSON.stringify(Dividends));
console.log("Add Dividend Cookie!!");
}
}
else
{
Dividends.push({"companyID": ID, "companyDividend": earnPerShare, "companyPrice": stockPrice, "companyStock": totalStock});
window.localStorage.setItem ("Dividend", JSON.stringify(Dividends));
console.log("AddDividendCookie!!");
}
}
/**************company****************/
/*************************************/
/************accountInfo**************/
var userManage;
var managerSalary = 0;
function addManagerSalaryInfo()
{
if ($('.card-title.mb-1').length > 0)
{
userManage = [];
managerSalary = 0;
var companyDividend, companyStock, dividendIndex;
var Dividends = null !== window.localStorage.getItem ("Dividend") ? JSON.parse(window.localStorage.getItem ("Dividend")) : [];
for (var manage = 0 ; manage < $('.text-primary').length ; ++manage)
{
//console.log("check " + manage);
if ($('.text-primary')[manage].innerHTML.match(/是「<a href="\/company\/detail\/([^]+)">/) !== null)
{
userManage.push($('.text-primary')[manage].innerHTML.match(/是「<a href="\/company\/detail\/([^]+)">/)[1]);
//這裡push的是companyID,不是companyName
console.log("manage " + manage + " " + userManage[manage]);
}
}
console.log("----------------------------");
console.log("start compute manager salary");
for (var m = 0 ; m < userManage.length ; m++)
{
companyStock = 0;
companyDividend = 0;
dividendIndex = Dividends.findIndex(b => b.companyID == userManage[m]);
if (dividendIndex != -1)
{
companyDividend = Number(Dividends[dividendIndex].companyDividend);
companyStock = Number(Dividends[dividendIndex].companyStock);
}
console.log("manage :" + userManage[m] + " salary: " + companyDividend * companyStock / 0.8075 * 0.05);
console.log("companyStock: " + companyStock + " companyDividend: " + companyDividend);
managerSalary += (((companyDividend * companyStock) / 0.8075) * 0.05);
}
console.log("managerSalary: " + managerSalary);
console.log("compute complete");
console.log("----------------------------");
var classManagerSalaryInfo = $("#managerSalaryInfoNumber");
if(classManagerSalaryInfo.length === 0)
{
if (managerSalary > 0)
{
$('<div class="media account-info-item border-grid-body" id = "managerSalaryInfo"><div class="col-6 text-right border-grid" id = "managerSalaryInfoTitle"><h2>' + Dict[lan].managerTotalSalary + '</h2></div></div>').insertAfter($('.card-title.mb-1')[0]);
$('<div class="col-6 text-right border-grid" id = "managerSalaryInfoNumber"><h2>$ ' + managerSalary.toFixed() + '</h2></div>').insertAfter($('#managerSalaryInfoTitle')[0]);
}
}
else
{
$("#managerSalaryInfoNumber")[0].innerHTML = "<h2>$ " + managerSalary.toFixed() + "</h2>";
}
}
else
{
setTimeout(addManagerSalaryInfo, 1000);
}
}
//userStcokInfo的格式:
//{"userID": CWgfhqxbrJMxsknrb, "userCompany": [{"companyID": aaa, "userHold": number}, {}], "userManage":[aaa, bbb, ccc]}
function callAddUserProfitInfo()
{
setTimeout(addUserProfitInfo, 1000);
console.log("callAddUserProfitInfo");
}
function addUserProfitInfo()
{
if ($('.card-title.mb-1').length > 0)
{
var classUserProfitInfo, userAssets = 0, userProfit = 0, userCompanyNumber = 0;
var cash = 0;
var userStockInfo = null !== window.sessionStorage.getItem ("userStockInfo") ? JSON.parse(window.sessionStorage.getItem ("userStockInfo")) : [];
var userID = document.location.href.match(/accountInfo\/([0-z]+)/)[1];
var userIndex = userStockInfo.findIndex(a => a.userID == userID);
var companyPrice, companyDividend, dividendIndex;
cash = Number($('.card-block')[0].innerText.match(/帳號當前餘額:([0-9]+)/)[1]);
var Dividends = null !== window.localStorage.getItem ("Dividend") ? JSON.parse(window.localStorage.getItem ("Dividend")) : [];
if (userIndex == -1)
{
console.log("no data in session, make new userInfo");
userStockInfo.push({"userID": userID, "userCompany": [], "userManage": userManage});
userIndex = userStockInfo.findIndex(a => a.userID == userID);
}
console.log("start compute stock profit");
for (var k in userStockInfo[userIndex].userCompany)
{
companyPrice = 0;
companyDividend = 0;
dividendIndex = Dividends.findIndex(b => b.companyID == userStockInfo[userIndex].userCompany[k].companyID);
if (dividendIndex != -1)
{
companyPrice = Number(Dividends[dividendIndex].companyPrice);
companyDividend = Number(Dividends[dividendIndex].companyDividend);
}
userAssets += companyPrice * userStockInfo[userIndex].userCompany[k].userHold;
userProfit += companyDividend * userStockInfo[userIndex].userCompany[k].userHold;
userCompanyNumber += 1;
}
console.log("compute complete");
console.log("start compute tax");
computeTax(userAssets + userProfit + managerSalary + cash);
tax = Math.ceil(output);
console.log("compute complete");
var classUserTaxInfo = $("#userTaxInfoNumber");
if(classUserTaxInfo.length === 0)
{
$('<div class="media account-info-item border-grid-body" id = "userTaxInfo"><div class="col-6 text-right border-grid" id = "userTaxInfoTitle"><h2>' + Dict[lan].userTotalTax + '</h2></div></div>').insertAfter($('.card-title.mb-1')[0]);
$('<div class="col-6 text-right border-grid" id = "userTaxInfoNumber"><h2>$ ' + tax + '</h2></div>').insertAfter($('#userTaxInfoTitle')[0]);
}
else
{
console.log("start update info");
$("#userTaxInfoNumber")[0].innerHTML = "<h2>$ " + tax + "</h2>";
}
classUserProfitInfo = $("#userProfitInfoNumber");
if(classUserProfitInfo.length === 0)
{
console.log("start add info");
$('<div class="media account-info-item border-grid-body" id = "userProfitInfo"><div class="col-6 text-right border-grid" id = "userProfitInfoTitle"><h2>' + Dict[lan].userTotalProfit + '</h2></div></div>').insertAfter($('.card-title.mb-1')[0]);
$('<div class="col-6 text-right border-grid" id = "userProfitInfoNumber"><h2>$ ' + userProfit.toFixed() + '</h2></div>').insertAfter($('#userProfitInfoTitle')[0]);
$('<div class="media account-info-item border-grid-body" id = "userAssetsInfo"><div class="col-6 text-right border-grid" id = "userAssetsInfoTitle"><h2>' + Dict[lan].userTotalAssets + '</h2></div></div>').insertAfter($('.card-title.mb-1')[0]);
$('<div class="col-6 text-right border-grid" id = "userAssetsInfoNumber"><h2>$ ' + userAssets + '</h2></div>').insertAfter($('#userAssetsInfoTitle')[0]);
$('<div class="media account-info-item border-grid-body" id = "userCompanyNumberInfo"><div class="col-6 text-right border-grid" id = "userCompanyNumberInfoTitle"><h2>' + Dict[lan].userTotalCompanyNumber + '</h2></div></div>').insertAfter($('.card-title.mb-1')[0]);
$('<div class="col-6 text-right border-grid" id = "userCompanyNumberInfoNumber"><h2> ' + userCompanyNumber + '</h2></div>').insertAfter($('#userCompanyNumberInfoTitle')[0]);
setTimeout(checkInfoEvent, 500);
}
else
{
console.log("start update info");
$("#userProfitInfoNumber")[0].innerHTML = "<h2>$ " + userProfit.toFixed() + "</h2>";
$("#userAssetsInfoNumber")[0].innerHTML = "<h2>$ " + userAssets + "</h2>";
$("#userCompanyNumberInfoNumber")[0].innerHTML = "<h2> " + userCompanyNumber + "</h2>";
}
}
else
{
setTimeout(callAddUserProfitInfo, 1000);
}
}
checkInfoAgain = 0;
function checkInfoEvent()
{
setTimeout(checkUserHoldStock, 500);
}
//userStcokInfo的格式:
//{"userID": CWgfhqxbrJMxsknrb, "userCompany": [{"companyID": aaa, "userHold": number}, {}], "userManage":[aaa, bbb, ccc]}
function checkUserHoldStock()
{
folderOpenString = "fa-folder-open";
folderCloseString = "fa-folder";
var userStockInfo = null !== window.sessionStorage.getItem ("userStockInfo") ? JSON.parse(window.sessionStorage.getItem ("userStockInfo")) : [];
var userID = document.location.href.match(/accountInfo\/([0-z]+)/)[1];
var userIndex = userStockInfo.findIndex(a => a.userID == userID);
if (userIndex == -1)
{
userStockInfo.push({"userID": userID, "userCompany": [], "userManage": []});
userIndex = userStockInfo.findIndex(a => a.userID == userID);
}
var Dividends = null !== window.localStorage.getItem ("Dividend") ? JSON.parse(window.localStorage.getItem ("Dividend")) : [];
var folderstate = $(".d-block.h4 i")[1].classList[1];
if (folderstate === folderOpenString)
{
//console.log("Open");
//Open Event
var companyID, i, holdStockElement, hold;
//var pageAssets = 0, pageProfit = 0, earnPerShare;
for(i = 0; i < 4 && i < $('.col-12.border-grid').length; ++i)
{
// 持股資訊只有可能在前四個col-12 border-grid中 先找出來
if($('.col-12.border-grid')[i].innerText.match(/擁有.+公司的.+股票/) !== null)
break;
}
var readCompanyNumber = 0;
var haveAnyDataChange = 0;
holdStockElement = $('.col-12.border-grid')[i];
for(var j = 0; j < holdStockElement.children.length; ++j)
{
if(holdStockElement.children[j].innerHTML.match(/href="(\/company[^"]+)/) !== null)
{
companyID = holdStockElement.children[j].innerHTML.match(/<a href="\/company\/detail\/([0-z]+)">/)[1];
var companyIndex = userStockInfo[userIndex].userCompany.findIndex(b => b.companyID == companyID);
hold = Number(holdStockElement.children[j].innerText.match(/擁有.+公司的([0-9]+)股股票/)[1]);
console.log("-----" + companyID + "-----" + hold + "-----");
if (companyIndex != -1)
{
if (Number(userStockInfo[userIndex].userCompany[companyIndex].userHold) == hold)
{
//console.log("dont need update this company");
}
else
{
haveAnyDataChange = 1;
userStockInfo[userIndex].userCompany.splice(companyIndex, 1);
userStockInfo[userIndex].userCompany.push({"companyID": companyID, "userHold": hold});
}
}
else
{
haveAnyDataChange = 1;
userStockInfo[userIndex].userCompany.push({"companyID": companyID, "userHold": hold});
}
readCompanyNumber += 1;
}
}
console.log("read company number: " + readCompanyNumber);
window.sessionStorage.setItem ("userStockInfo", JSON.stringify(userStockInfo));
if ( ((readCompanyNumber < 10) || (haveAnyDataChange == 0)) && (checkInfoAgain < 3))
{
checkInfoAgain += 1;
setTimeout(checkInfoEvent, 1000);
}
else
{
checkInfoAgain = 0;
callAddUserProfitInfo();
var pagesBtn = $(".page-item");
for(var k = 0; k < pagesBtn.length; k++)
pagesBtn[k].addEventListener("click", checkInfoEvent2);
}
}
else if (folderstate === folderCloseString)
{
setTimeout(checkInfoEvent, 1000);
}
}
function checkInfoEvent2()
{
setTimeout(checkUserHoldStock, 1000);
}
//搬運自papago腳本
const taxlimit = [10000, 100000, 500000, 1000000];
const taxalllimit = 1000000;
const taxpecent = 0.03;
function computeTax(money) {
let input = money;
console.log(input);
if (!input || 0 === input.length) {
console.log("N");
return;
}
output = 0;
let lastlimit = 0;
for (let i = 0;; i++) {
let limit = taxalllimit;
let tax = taxpecent * i;
if (i < taxlimit.length) {
limit = taxlimit[i] - lastlimit;
}
if (tax > 0.6) {
tax = 0.6;
output += input * tax;
break;
} else {
if (input < limit) {
output += input * tax;
break;
} else {
output += limit * tax;
input -= limit;
lastlimit += limit;
}
}
}
//$("#output").text("$ " + Math.ceil(output));
}
/************accountInfo**************/
/*************************************/
/************foundationPlan***********/
//-----已刪除
/************foundationPlan***********/
/**************aboutMe****************/
// -----已刪除
/**************aboutMe****************/
/*************Language***************/
var lan = "";
lan = null !== window.localStorage.getItem ("PM_language") ? window.localStorage.getItem ("PM_language") : "tw";
/*function ChangeLanguage(l){
if(lan === l)return;
lan = l;
window.localStorage.setItem ("PM_language",l);
window.location.reload();
}*/
var Dict = {
tw:
{
totalProfitInThisPage: "本頁預計分紅:",
updateDividendScript: "更新預估分紅腳本",
userTotalAssets: "使用者股票總值:",
userTotalProfit: "預估股票分紅:",
userTotalCompanyNumber: "持有公司總數:",
managerTotalSalary: "預估經理薪水:",
userTotalTax: "預估本季稅金:",
PEratio: "本益比排行",
stockPEInfo: "本益比",
},
en:
{
totalProfitInThisPage: "Total profit in this page :",
updateDividendScript: "Update Dividend Script",
userTotalAssets: "使用者股票總值:",
userTotalProfit: "預估股票分紅:",
userTotalCompanyNumber: "持有公司總數:",
managerTotalSalary: "預估經理薪水:",
userTotalTax: "預估本季稅金:",
PEratio: "本益比排行",
stockPEInfo: "本益比",
},
jp:
{
totalProfitInThisPage: "本頁預計分紅:",
updateDividendScript: "更新預估分紅腳本",
userTotalAssets: "使用者股票總值:",
userTotalProfit: "預估股票分紅:",
userTotalCompanyNumber: "持有公司總數:",
managerTotalSalary: "預估經理薪水:",
userTotalTax: "預估本季稅金:",
PEratio: "本益比排行",
stockPEInfo: "本益比",
},
marstw:
{
totalProfitInThisPage: "這ㄘ可yee拿ㄉ$$:",
updateDividendScript: "有★版",
userTotalAssets: "股票ㄉ$$:",
userTotalProfit: "這ㄘ會拿ㄉ$$:",
userTotalCompanyNumber: "偶ㄐ間公ㄙ:",
managerTotalSalary: "雞李ㄉ西水:",
userTotalTax: "ㄋ要交ㄉ茄:",
PEratio: "本益比排行",
stockPEInfo: "本益比",
}
};
/*************Language***************/
/*************Subscribe***************/
// -----已刪除
/*************Subscribe***************/