ACGN股票系統每股營利外掛

try to take over the world!

  1. // ==UserScript==
  2. // @name ACGN股票系統每股營利外掛
  3. // @namespace http://tampermonkey.net/
  4. // @version 3.900
  5. // @description try to take over the world!
  6. // @author papago & Ming & frozenmouse
  7. // @match http://acgn-stock.com/*
  8. // @match https://acgn-stock.com/*
  9. // @match https://test.acgn-stock.com/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. /**
  14. * 版本號格式為:a.bcc
  15. * a 為主要版本號,一位數
  16. * b 為次要版本號,一位數
  17. * c 為錯誤修正版本號,兩位數
  18. *
  19. * e.g., 版本號 2.801 => a = '2', b = '8', c = '01'
  20. *
  21. * 修復導致功能失效的錯誤或更新重大功能 → 提升主要或次要版本號
  22. * 優化 UI、優化效能、優化小錯誤 → 更新錯誤版本號
  23. *
  24. * 檢查更新時,若主要或次要版本號變動,則顯示按鍵提示使用者更新
  25. * (參見 checkScriptUpdates())
  26. */
  27.  
  28. const {dbCompanies} = require("./db/dbCompanies");
  29. const {dbDirectors} = require("./db/dbDirectors");
  30.  
  31. // 用公司資訊算出 EPS 與本益比
  32. function computeEpsAndPeRatio({totalRelease, profit, listPrice}) {
  33. const eps = profit * 0.75 / totalRelease;
  34. const peRatio = listPrice / eps;
  35. return {eps, peRatio};
  36. }
  37.  
  38. // 取得 Template 的 helpers
  39. Template.prototype.getHelper = function(name) {
  40. return this.__helpers[` ${name}`];
  41. };
  42.  
  43. // 包裝 Template 的 onRendered,加入自訂動作
  44. Template.prototype.oldOnRendered = Template.prototype.onRendered;
  45. Template.prototype.onRendered = function(callback) {
  46. // 在添加 onRendered callback 時一併記錄起來
  47. this.customOnRenderedCallbacks = this.customOnRenderedCallbacks || [];
  48. this.customOnRenderedCallbacks.push(callback);
  49.  
  50. // 在真正執行到 callback 之後記錄起來
  51. this.oldOnRendered(() => {
  52. const instance = Template.instance();
  53. callback();
  54. instance.customOnRenderedCalled = true;
  55. });
  56. };
  57.  
  58. // 計算該頁面所持有的股票總額並顯示
  59. Template.companyList.onRendered(() => {
  60. const totalAssetsDisplay = $(`
  61. <div class="media company-summary-item border-grid-body">
  62. <div class="col-6 text-right border-grid">
  63. <h2>${t("totalAssetsInThisPage")}</h2>
  64. </div>
  65. <div class="col-6 text-right border-grid">
  66. <h2 id="total-assets-result"></h2>
  67. </div>
  68. </div>
  69. `);
  70.  
  71. const instance = Template.instance();
  72. instance.autorun(() => {
  73. const ownStocks = dbDirectors.find({ userId: Meteor.userId() }).fetch();
  74. const companies = dbCompanies.find().fetch().reduce((obj, c) => Object.assign(obj, {[c._id]: c}), {});
  75. const totalAssets = ownStocks.filter(({companyId}) => companies[companyId])
  76. .reduce((sum, {companyId, stocks}) => sum + companies[companyId].listPrice * stocks, 0);
  77. console.log(`totalAssets = ${totalAssets}`);
  78.  
  79. instance.$(".card-title.mb-1").after(totalAssetsDisplay);
  80. totalAssetsDisplay.find("#total-assets-result").html(`$ ${totalAssets}`);
  81. });
  82. });
  83.  
  84. // 增加更多資訊在股市總覽的公司卡片上
  85. Template.companyListCard.onRendered(() => {
  86. function insertAfterLastRow(row) {
  87. instance.$(".row-info").last().after(row);
  88. }
  89.  
  90. function hideRow(row) {
  91. row.removeClass("d-flex").addClass("d-none");
  92. }
  93.  
  94. function showRow(row) {
  95. row.removeClass("d-none").addClass("d-flex");
  96. }
  97.  
  98. const instance = Template.instance();
  99. const getStockAmount = Template.companyListCard.getHelper("getStockAmount");
  100. const infoRowSample = instance.$(".row-info").last();
  101.  
  102. const ownValueRow = infoRowSample.clone();
  103. ownValueRow.find("p:eq(0)").html("持有總值");
  104. insertAfterLastRow(ownValueRow);
  105.  
  106. const profitRow = infoRowSample.clone();
  107. profitRow.find("p:eq(0)").html("本季營利");
  108. insertAfterLastRow(profitRow);
  109.  
  110. const peRatioRow = infoRowSample.clone();
  111. peRatioRow.find("p:eq(0)").html("本益比");
  112. insertAfterLastRow(peRatioRow);
  113.  
  114. const peRatioInverseRow = infoRowSample.clone();
  115. peRatioInverseRow.find("p:eq(0)").html("益本比");
  116. insertAfterLastRow(peRatioInverseRow);
  117.  
  118. const dividendRow = infoRowSample.clone();
  119. dividendRow.find("p:eq(0)").html("預計分紅");
  120. insertAfterLastRow(dividendRow);
  121.  
  122. const managerSalaryRow = infoRowSample.clone();
  123. managerSalaryRow.find("p:eq(0)").html("經理薪水");
  124. insertAfterLastRow(managerSalaryRow);
  125.  
  126. instance.autorun(() => {
  127. const companyData = Template.currentData();
  128. const {_id: companyId, profit, totalRelease, listPrice, manager} = companyData;
  129. const {peRatio} = computeEpsAndPeRatio(companyData);
  130.  
  131. profitRow.find("p:eq(1)").html(`$ ${Math.round(profit)}`);
  132. peRatioRow.find("p:eq(1)").html(isFinite(peRatio) ? peRatio.toFixed(2) : "∞");
  133. peRatioInverseRow.find("p:eq(1)").html((1 / peRatio).toFixed(2));
  134.  
  135. if (!Meteor.user()) {
  136. hideRow(ownValueRow);
  137. hideRow(dividendRow);
  138. hideRow(managerSalaryRow);
  139. } else {
  140. const stockAmount = getStockAmount(companyId);
  141. const ownValue = stockAmount * listPrice;
  142. ownValueRow.find("p:eq(1)").html(`$ ${ownValue}`);
  143. showRow(ownValueRow);
  144.  
  145. const dividend = Math.round(profit * 0.8 * stockAmount / totalRelease);
  146. dividendRow.find("p:eq(1)").html(`$ ${dividend}`);
  147. showRow(dividendRow);
  148.  
  149. if (Meteor.userId() !== manager) {
  150. hideRow(managerSalaryRow);
  151. } else {
  152. const managerSalary = Math.round(profit * 0.05);
  153. managerSalaryRow.find("p:eq(1)").html(`$ ${managerSalary}`);
  154. showRow(managerSalaryRow);
  155. }
  156. }
  157. });
  158. });
  159.  
  160. // 在新創列表加入預計股價、個人股權資訊
  161. Template.foundationListCard.onRendered(() => {
  162. function insertAfterLastRow(row) {
  163. instance.$(".row-info").last().after(row);
  164. }
  165.  
  166. const instance = Template.instance();
  167.  
  168. const infoRowSample = instance.$(".row-info").last();
  169.  
  170. const stockPriceRow = infoRowSample.clone();
  171. stockPriceRow.find("p:eq(0)").html(t("foundationPlanStockPrice"));
  172. insertAfterLastRow(stockPriceRow);
  173.  
  174. const personalStockAmountRow = infoRowSample.clone();
  175. personalStockAmountRow.find("p:eq(0)").html(t("foundationPlanShare"));
  176. insertAfterLastRow(personalStockAmountRow);
  177.  
  178. const personalStockRightRow = infoRowSample.clone();
  179. personalStockRightRow.find("p:eq(0)").html(t("foundationPlanStock"));
  180. insertAfterLastRow(personalStockRightRow);
  181.  
  182. instance.autorun(() => {
  183. const foundationData = Template.currentData();
  184. const totalFund = foundationData.invest.reduce((sum, {amount}) => sum + amount, 0);
  185. const stockPrice = computeStockPriceFromTotalFund(totalFund);
  186.  
  187. const currentUserId = Meteor.userId();
  188. const personalInvest = foundationData.invest.find(i => i.userId === currentUserId);
  189. const personalFund = personalInvest ? personalInvest.amount : 0;
  190. const personalStockAmount = Math.floor(personalFund / stockPrice);
  191. const personalStockRight = personalFund / totalFund;
  192.  
  193. stockPriceRow.find("p:eq(1)").html(`$ ${stockPrice}`);
  194. personalStockAmountRow.find("p:eq(1)").html(`${personalStockAmount} 股`);
  195. personalStockRightRow.find("p:eq(1)").html(`${(personalStockRight * 100).toFixed(2)} %`);
  196. });
  197. });
  198.  
  199. // 從總投資額推算新創公司的預計股價
  200. function computeStockPriceFromTotalFund(totalFund) {
  201. let result = 1;
  202. while (totalFund / 1000 > result) result *= 2;
  203. return Math.max(1, result / 2);
  204. }
  205.  
  206. // 新增插件功能按鈕至上面的導覽區
  207. function addPluginDropdownMenu() {
  208. // 所有按鍵插入在原來的第三個按鍵(主題配置)之後
  209. // 按鍵需要以倒序插入,後加的按鍵會排在左邊
  210. const insertionTarget = $(".note")[2];
  211.  
  212. const pluginDropdown = $(`
  213. <div class="note">
  214. <li class="nav-item dropdown">
  215. <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown">${t("pluginDropdown")}</a>
  216. <div class="dropdown-menu px-3" aria-labelledby="navbarDropdownMenuLink" style="display: none;" id="lang-menu">
  217. <a class="nav-link" href="#" id="block-ads">${t("blockAds")}</a>
  218. <h6 class="dropdown-header" style="padding: 0.5rem 0rem">${t("language")}</h6>
  219. <a class="nav-link" href="#" id="lang-tw">台灣話</a>
  220. <a class="nav-link" href="#" id="lang-marstw">ㄏㄒㄨ</a>
  221. <a class="nav-link" href="#" id="lang-en">English</a>
  222. <a class="nav-link" href="#" id="lang-jp">日本語</a>
  223. <div class="dropdown-divider"/>
  224. <a class="nav-link" href="#" id="about-script">${t("aboutScript")}</a>
  225. </div>
  226. </li>
  227. </div>
  228. `);
  229. pluginDropdown.insertAfter(insertionTarget);
  230. pluginDropdown.find("#lang-tw").on("click", () => { changeLanguage("tw"); });
  231. pluginDropdown.find("#lang-marstw").on("click", () => { changeLanguage("marstw"); });
  232. pluginDropdown.find("#lang-en").on("click", () => { changeLanguage("en"); });
  233. pluginDropdown.find("#lang-jp").on("click", () => { changeLanguage("jp"); });
  234. pluginDropdown.find("#about-script").on("click", showAboutScript);
  235. pluginDropdown.find("#block-ads").on("click", blockAds);
  236. }
  237.  
  238. // 對所有廣告點擊關閉
  239. function blockAds() {
  240. $(".fixed-bottom a.btn").click();
  241. }
  242.  
  243. /*************************************/
  244. /************ 腳本更新檢查 *************/
  245.  
  246. // 腳本檢查更新的週期
  247. const updateScriptCheckInterval = 600000; // 10 分鐘
  248.  
  249.  
  250. // 檢查腳本是否有更新
  251. function checkScriptUpdates() {
  252. checkGreasyForkScriptUpdate("33359"); // papago 版
  253. checkGreasyForkScriptUpdate("33781"); // Ming 版
  254. checkGreasyForkScriptUpdate("33814"); // frozenmouse 版
  255.  
  256. // 在經過了一段時間之後,再檢查一次
  257. setTimeout(checkScriptUpdates, updateScriptCheckInterval);
  258. }
  259.  
  260. // 將版本號字串拆解成 major, minor, patch
  261. function parseVersion(versionString) {
  262. const [head, rest] = versionString.split(".");
  263. const major = Number.parseInt(head);
  264. const minor = Number.parseInt(rest.substring(0, 1));
  265. const patch = Number.parseInt(rest.substring(1));
  266. return {major, minor, patch};
  267. }
  268.  
  269. // 檢查 GreasyFork 上特定 id 的腳本是否有更新
  270. function checkGreasyForkScriptUpdate(id) {
  271. const scriptUrl = `https://greasyfork.org/zh-TW/scripts/${id}`;
  272. const request = new XMLHttpRequest();
  273.  
  274. request.open("GET", `${scriptUrl}.json`);
  275. request.addEventListener("load", function() {
  276. const remoteVersion = parseVersion(JSON.parse(this.responseText).version);
  277. const localVersion = parseVersion(GM_info.script.version);
  278.  
  279. console.log(`檢查 GreasyFork 腳本版本:id = ${id}, remoteVersion = ${JSON.stringify(remoteVersion)}, localVersion = ${JSON.stringify(localVersion)}`);
  280.  
  281. // 只有 major 或 minor 變動才通知更新
  282. const isUpdateNeeded = remoteVersion.major > localVersion.major
  283. || (remoteVersion.major === localVersion.major && remoteVersion.minor > localVersion.minor);
  284.  
  285. if (isUpdateNeeded && $(`#update-script-button-greasy-${id}`).length === 0) {
  286. $(`
  287. <li class="nav-item">
  288. <a class="nav-link btn btn-primary" href="${scriptUrl}" id="update-script-button-greasy-${id}" target="_blank">${t("updateScript")}</a>
  289. </li>
  290. `).insertAfter($(".nav-item").last());
  291. }
  292. });
  293. request.send();
  294. }
  295. /************ 腳本更新檢查 *************/
  296. /*************************************/
  297.  
  298.  
  299. /***************************************/
  300. /************** 關於插件 ****************/
  301.  
  302. // 顯示插件資訊
  303. function showAboutScript() {
  304. // (暴力地)移除目前頁面的顯示資訊…
  305. $(".card-block").remove();
  306.  
  307. // …並改成顯示插件資訊
  308. $(".card").append(`
  309. <div class="card-block">
  310. <div class="col-5"><h1 class="card-title mb-1">關於插件</h1></div>
  311. <div class="col-5">by papago89, Ming, frozenmouse</div>
  312. <div class="col-12">
  313. <hr>
  314. <p>要離開本頁面記得點進來的那一頁以外的其他頁面</p>
  315. <hr>
  316. <p>
  317. 本插件功能不定時增加中,目前功能有以下幾個:
  318. <ul>
  319. <li>在頁面<span class="text-info">股市總覽</span>可以查看本頁股票總值,建議開啟<span class="text-info">只列出我所持有的股票</span></li>
  320. <li>在頁面<span class="text-info">新創計畫</span>可以查看推測股價、推測股權、推測應得股數</li>
  321. <li>在頁面<span class="text-info">新創計畫</span>搜尋欄鍵入文字時會提示股市總覽中是否已存在相同名稱或標籤之公司</li>
  322. <li>在各公司頁面數據資訊處增加每股盈餘、本益比、益本比</li>
  323. <li>在頁面<span class="text-info">帳號資訊</span>增加稅金試算,輸入總資產後就會算出你應該繳的稅金</li>
  324. <li>在頁面<span class="text-info">帳號資訊</span>增加資產換算</li>
  325. <li>按鈕<span class="text-info">廣告關閉</span>隱藏所有廣告讓你什麼都看不到</li>
  326. <li>在頁面<span class="text-info">關於插件</span>增加插件功能介紹,版本更新紀錄,還有廢話</li>
  327. <li>按鈕<span class="text-info">點我更新插件</span>在greasyfork有新版本時會自動跳出提示大家更新</li>
  328. <li>按鈕<span class="text-info">選擇語言</span>可以更改語言,不過要重新整理頁面才會生效</li>
  329. </ul>
  330. </p>
  331. <hr>
  332. <p>有任何問題或建議請到Discord:ACGN Stock留言</p>
  333. <p><a href="https://greasyfork.org/zh-TW/scripts/33814" target="_blank">更新插件</a></p>
  334. </div>
  335. </div>
  336.  
  337. <div class="card-block">
  338. <div class="row border-grid-body" style="margin-top: 15px;">
  339. <div class="col-12 border-grid" id="release-history-folder">
  340. <a class="d-block h4" href="" data-toggle-panel="update">更新紀錄 <i class="fa fa-folder" aria-hidden="true" /></a>
  341. </div>
  342. </div>
  343. </div>
  344. `);
  345.  
  346. // 「更新記錄」資料夾
  347. const releaseHistoryFolder = $("#release-history-folder");
  348. releaseHistoryFolder.on("click", () => {
  349. const releaseHistoryFolderIcon = releaseHistoryFolder.find(".fa");
  350. if (releaseHistoryFolderIcon.hasClass("fa-folder")) {
  351. // 資料夾打開,顯示更新記錄
  352. releaseHistoryFolderIcon.removeClass("fa-folder").addClass("fa-folder-open");
  353. releaseHistoryFolder.after((releaseHistoryList.map(({ version, description }) => createReleaseHistoryDiv(version, description)).join("")));
  354. } else {
  355. // 資料夾關閉,移除更新記錄
  356. releaseHistoryFolderIcon.removeClass("fa-folder-open").addClass("fa-folder");
  357. releaseHistoryFolder.nextAll(".col-12.border-grid").remove();
  358. }
  359. });
  360. }
  361.  
  362. // 更新紀錄列表
  363. const releaseHistoryList = [
  364. {
  365. version: "3.000",
  366. description: `
  367. <p>幾乎全部打掉重練,使用更有效率的方式與頁面結合。</p>
  368. <p><span class="text-info">股市總覽</span>新增顯示個股持有總值、本季營利、本益比、預計分紅、與經理薪水。</p>
  369. <p><span class="text-info">帳號資訊</span>移除統計分紅功能,請使用<a href="https://greasyfork.org/zh-TW/scripts/33542">ACGN-stock營利統計外掛 by SoftwareSing</a>。</p>
  370. <p><span class="text-info">新創計畫</span>暫時移除搜尋已存在公司功能(未來想辦法加回)。</p>
  371. `,
  372. },
  373. {
  374. version: "2.810",
  375. description: `<p><span class="text-info">股市總覽</span>與<span class="text-info">新創計劃</span>增加了跳頁功能,可直接跳至指定頁數。</p>`,
  376. },
  377. {
  378. version: "2.800",
  379. description: `
  380. <p>滿滿的大重構。</p>
  381. <p><span class="text-info">更新腳本</span>增加了與frozenmouse發佈版本的連動。</p>
  382. `,
  383. },
  384. {
  385. version: "2.500",
  386. description: `<p><span class="text-info">更新腳本</span>連動到Ming,現在Ming也可以自己發布新版腳本讓大家更新了。</p>`,
  387. }, {
  388. version: "2.300",
  389. description: `<p>移除<span class="text-info">訂閱</span>功能</p>`,
  390. }, {
  391. version: "2.200",
  392. description: `
  393. <p>新增<span class="text-info">新創搜尋提示</span>功能</p>
  394. <p>新增<span class="text-info">帳號頁面持股換算資產</span>功能</p>
  395. `,
  396. }, {
  397. version: "2.000",
  398. description: `<p>新增<span class="text-info">訂閱</span>功能</p>`,
  399. }, {
  400. version: "1.900",
  401. description: `<p>新增<span class="text-info">選擇語言</span></p>`,
  402. }, {
  403. version: "1.800",
  404. description: `<p>新增<span class="text-info">點我更新插件</span>按鈕</p>`,
  405. }, {
  406. version: "1.73",
  407. description: `
  408. <p><span class="text-info">更新插件</span>連結現在會在新分頁開啟連結,讓原本的頁面可以繼續看股票。</p>
  409. <p>修正<span class="text-info">關於插件</span>中,更新紀錄排序錯亂的問題。</p>
  410. <p>新增<span class="text-info">新創計畫</span>下,列表模式的推測股價、推測股權、推測應得股數。</p>
  411. <p>優化一些日誌顯示,讓開發人員在除錯更方便一些。</p>
  412. `,
  413. }, {
  414. version: "1.72",
  415. description: `
  416. <p>優化<span class="text-info">廣告關閉</span>功能。</p>
  417. <p>好像還有新增一些功能什麼的。</p>
  418. `,
  419. }, {
  420. version: "1.70",
  421. description: `<p>新增功能<span class="text-info">廣告關閉</span>將會隱藏所有廣告,按過後只要不關閉頁面你就再也看不到任何廣告了,包含公告以及新發布的廣告。</p>`,
  422. }, {
  423. version: "1.63",
  424. description: `<p>修正<span class="text-info">股市總覽</span>中列表模式如果出現有交易尚未完成會造成計算錯誤</p>`,
  425. }, {
  426. version: "1.62",
  427. description: `<p>新增頁面<span class="text-info">關於插件</span></p>`,
  428. }, {
  429. version: "1.61以前",
  430. description: `<p>新增了一些功能,不過不是很重要</p>`,
  431. },
  432. ];
  433.  
  434. // 建立對應版本的更新說明
  435. function createReleaseHistoryDiv(version, description) {
  436. return `
  437. <div class="col-12 border-grid">
  438. <h4>版本${version}:</h4>
  439. ${description}
  440. </div>
  441. `;
  442. }
  443. /************** 關於插件 ****************/
  444. /***************************************/
  445.  
  446. /**************************************/
  447. /************* 語言相關 ****************/
  448.  
  449. // 目前的語言
  450. let currentLanguage = window.localStorage.getItem("PM_language") || "tw";
  451.  
  452. // 切換顯示語言
  453. function changeLanguage(language) {
  454. if (currentLanguage === language) return;
  455. currentLanguage = language;
  456. window.localStorage.setItem("PM_language", language);
  457. window.location.reload();
  458. }
  459.  
  460. // 翻譯米糕
  461. function t(key) {
  462. return dict[currentLanguage][key];
  463. }
  464.  
  465. // 翻譯表
  466. const dict = {
  467. tw: {
  468. pluginDropdown: "papago插件",
  469. language: "選擇語言",
  470. blockAds: "關閉廣告",
  471. aboutScript: "關於插件",
  472. updateScript: "更新腳本",
  473. totalAssetsInThisPage: "本頁股票總值:",
  474. benefitRatio: "益本比:",
  475. PERatio: "本益比:",
  476. earnPerShare: "每股盈餘:",
  477. taxCalculation: "稅金試算",
  478. enterTotalAssets: "輸入你的總資產:",
  479. yourTax: "你應繳的稅金:",
  480. foundationPlanStock: "當前股權應為:",
  481. foundationPlanShare: "當前投資應得:",
  482. foundationPlanStockPrice: "當前股價應為:",
  483. subscribe: "訂閱公司",
  484. unsubscribe: "取消訂閱",
  485. showMySubscribes: "我的訂閱",
  486. goToCompany: "前往",
  487. },
  488. en: {
  489. pluginDropdown: "papago Plugin",
  490. language: "language",
  491. blockAds: "Block Ad",
  492. aboutScript: "About Script",
  493. updateScript: "Update Script",
  494. totalAssetsInThisPage: "Total assets in this page :",
  495. benefitRatio: "benefit ratio :",
  496. PERatio: "P/E ratio :",
  497. earnPerShare: "Earning per share :",
  498. taxCalculation: "Tax calculation",
  499. enterTotalAssets: "Enter your total assets :",
  500. yourTax: "your tax :",
  501. foundationPlanStock: "Your stock :",
  502. foundationPlanShare: "your investment will get",
  503. foundationPlanStockPrice: "Stock price :",
  504. subscribe: "Subscribe",
  505. unsubscribe: "Unsubscribe",
  506. showMySubscribes: "My Subscription",
  507. goToCompany: "Go to company ",
  508. },
  509. jp: {
  510. pluginDropdown: "papago プラグイン",
  511. language: "言語を選択",
  512. blockAds: "広告を閉じる",
  513. aboutScript: "プラグインについて",
  514. updateScript: "スクリプトを更新する",
  515. totalAssetsInThisPage: "このページの株式時価総額:",
  516. benefitRatio: "株式益回り:",
  517. PERatio: "株価収益率:",
  518. earnPerShare: "一株利益:",
  519. taxCalculation: "税金計算",
  520. enterTotalAssets: "総資産を入力する:",
  521. yourTax: "あなたの税金:",
  522. foundationPlanStock: "予想の持株比率:",
  523. foundationPlanShare: "予想の株式持分:",
  524. foundationPlanStockPrice: "予想の株価:",
  525. subscribe: "訂閱公司",
  526. unsubscribe: "取消訂閱",
  527. showMySubscribes: "我的訂閱",
  528. goToCompany: "前往",
  529. },
  530. marstw: {
  531. pluginDropdown: "%%狗ㄉ外掛",
  532. language: "顯4ㄉ語言",
  533. blockAds: "關ㄅ廣告",
  534. aboutScript: "我做ㄌ什麼",
  535. updateScript: "有☆版",
  536. totalAssetsInThisPage: "這一ya的股票一共ㄉ錢:",
  537. benefitRatio: "yee本比:",
  538. PERatio: "本yee比:",
  539. earnPerShare: "每ㄍ股票ㄉ或立:",
  540. taxCalculation: "歲金計算",
  541. enterTotalAssets: "你ㄉ錢:",
  542. yourTax: "要交ㄉ稅金:",
  543. foundationPlanStock: "你占多少趴:",
  544. foundationPlanShare: "你有多少股:",
  545. foundationPlanStockPrice: "股價因該4:",
  546. subscribe: "訂閱這ㄍ工ㄙ",
  547. unsubscribe: "不訂閱這ㄍ工ㄙ",
  548. showMySubscribes: "窩ㄉ訂閱",
  549. goToCompany: "窩要ㄑ找",
  550. },
  551. };
  552. /************* 語言相關 ****************/
  553. /**************************************/
  554.  
  555. function findAncestorViews(view) {
  556. if (!view.parentView) return [];
  557.  
  558. const ancestorViews = [];
  559. let ancestorView = view.parentView;
  560. while (ancestorView) {
  561. ancestorViews.push(ancestorView);
  562. ancestorView = ancestorView.parentView;
  563. }
  564. return ancestorViews;
  565. }
  566.  
  567. // 手動觸發新加入的 onRendered
  568. function manuallyTriggerCustomOnRendered() {
  569. function check() {
  570. $("*").toArray()
  571. .map(e => Blaze.getView(e))
  572. .flatMap(v => v ? [v, ...findAncestorViews(v)] : [])
  573. .forEach(view => {
  574. if (!view || !view.templateInstance) return;
  575.  
  576. const instance = view.templateInstance();
  577. const callbacks = view.template.customOnRenderedCallbacks || [];
  578.  
  579. if (callbacks.length === 0 || instance.customOnRenderedCalled) return;
  580.  
  581. console.log("call custom onRendered", instance);
  582. callbacks.forEach(callback => Template._withTemplateInstanceFunc(view.templateInstance, callback));
  583. instance.customOnRenderedCalled = true;
  584. });
  585. }
  586.  
  587. const loopInterval = 500;
  588. const loopLimit = 5;
  589. let loopCount = 0;
  590.  
  591. check();
  592. const intervalHandle = setInterval(() => {
  593. check();
  594. loopCount++;
  595. if (loopCount > loopLimit) {
  596. clearInterval(intervalHandle);
  597. }
  598. } , loopInterval);
  599. }
  600.  
  601. // ======= 主程式 =======
  602. (function() {
  603. manuallyTriggerCustomOnRendered();
  604. addPluginDropdownMenu();
  605. checkScriptUpdates();
  606. })();