jisilux

在jsl与xueqiu同品种页面间跳转,从xueqiu转到jsl有地址不对的情况,jsl里lof\etf中包含的qdii、封基是分开的,没找到代码上的规律。

目前為 2024-03-03 提交的版本,檢視 最新版本

// ==UserScript==
// @name         jisilux
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  在jsl与xueqiu同品种页面间跳转,从xueqiu转到jsl有地址不对的情况,jsl里lof\etf中包含的qdii、封基是分开的,没找到代码上的规律。
// @author       [email protected]
// @license      https://www.apache.org/licenses/LICENSE-2.0
// @include      https://*jisilu.cn/data/*
// @include      https://*xueqiu.com/*
// @connect      192.168.196.9
// @icon         https://www.jisilu.cn/favicon.ico
// @grant        GM_xmlhttpRequest
// @run-at document-end
// ==/UserScript==

(function() {
    'use strict'
    const xqUrl = 'https://xueqiu.com/S/'
    const jslUrl = 'https://www.jisilu.cn/data/'
    const sh = /^(11|50|51|56|58|60|68|70|73|90)\d{4}$/ // 沪市证券
    const sz = /^(00|08|12|15|16|20|30)\d{4}$/ // 深市证券
    const bj = /^(83|87|88)\d{4}$/ //北交所
    const cb = /^(110|113|123|127|128)\d{3}$/ // 可转债
    const etf = /^(15|51|56|58)\d{4}$/ //这个跳到jsl会有错漏,ETF中的qdii ,jsl是分开的。没有找到分开的规律。
    const stock = /^(600|601|603|688|000|002|300)\d{3}$/ //这个不知道有错漏没,没有包括北交所。
    const lof = /^(16|50)\d{4}$/ //这个错的最多,qdii 封闭基金 都有可能,没有找到规律。
    const server = 'http://192.168.196.9:9096/indicator'
    //preStart
    function purifyCode(code) {
        return code.replace(/[a-z]*/gi, '')
    }
    function addPrefix(code) {
        code = purifyCode(code)
        if (sh.test(code)) {
            return 'SH' + String(code)}
        else if (sz.test(code)) {
            return 'SZ' + String(code)}
        else if (bj.test(code)) {
            return 'BJ' + String(code)}
        else {
            return false
        }
    }
    function classify(code) {
        code = purifyCode(code)
        if (cb.test(code)) {
            return jslUrl.concat('convert_bond_detail/',code)
        } else if (etf.test(code)) {
            return jslUrl.concat('etf/detail/',code)
        } else if (stock.test(code)) {
            return jslUrl.concat('stock/detail/',code)
        } else if (lof.test(code)) {
            return jslUrl.concat('lof/detail/',code)
        } else {
            return false
        }
    }
    function fetchIndicator(code){
        let url = server + '?stocks='+ String(code)
        var res
        GM_xmlhttpRequest({
            method: 'GET',
            url: url,
            onload: function(response) {
                let indicator
                res = JSON.parse(response.response)
                let EPS = /\d+\.\d+/.exec($('#app .quote-info')[0].innerHTML.match(/每股收益\D+\d+\.\d+/)[0])[0]
                let BVPS = /\d+\.\d+/.exec($('#app .quote-info')[0].innerHTML.match(/每股净资产\D+\d+\.\d+/)[0])[0]
                let roe = (parseFloat(EPS)/parseFloat(BVPS)*100).toFixed(1)
                if (res) {
                    let alr = res.alr.toFixed(1)
                    let alrColor = alr > 50 ? '#dd2200':'#093'
                    indicator = `<a class="stock-relation"><span>Roe </span><span style='color:#07d'>${roe}% </span><span >负债 </span><span style='color:${alrColor}'>${alr}% </span></a>`
                } else {
                    indicator = `<a class="stock-relation"><span>Roe </span><span style='color:#07d'>${roe}% </span></a>`
                }
                $('#app .stock-info').eq(0).after(indicator)
                new MutationObserver((recordList) => {
                    if (recordList[0].removedNodes.length!=0){
                        $('#app .stock-info').eq(0).after(indicator)
                    }
                }).observe( document.querySelector( 'div.quote-container' ), {
                    childList: true
                })
            },
            onerror: function(error) {
                console.error("Request failed:", error)
            }
        })
    }
    // start
    window.addEventListener('load', function() {
        let code = location.pathname.split('/').pop()
        if (location.hostname.replace('www.', '') === 'jisilu.cn') {
            let fullCode = addPrefix(code)
            if (!fullCode) { return }
            let xqUrlDetail = xqUrl.concat(fullCode)
            let xq = `<div style="flex:1 1 auto;"><a href= ${xqUrlDetail} target='_blank'> <img src='https://xueqiu.com/favicon.ico' width="20px" /></a></div>`
            let xq2 = `<li><a href= ${xqUrlDetail} target='_blank'> <img src='https://xueqiu.com/favicon.ico' width="18px" /></a></li>`
            if ( $('#compare_top').length > 0 ) {
                $('#compare_top > .left_title').after(xq)
            }
            if ( $('ol.breadcrumb').length > 0) {
                $('ol.breadcrumb > li.active').after(xq2)
            }
        }
        //
        if (location.hostname.replace('www.', '') === 'xueqiu.com') {
            if (location.pathname.match(/^\/[0-9]{10}\/[0-9]{8}/)) {
                [...document.querySelectorAll('div.article__container')].forEach(item=>{
                    item.oncopy = function(e) {
                        e.stopPropagation()
                    }
                })
                $('.article__bd__detail h-char').removeClass('bd-hangable')
            } else if (location.pathname.match(/^\/S\//)) {
                if (code.match('S[HZ]')&&stock.test(purifyCode(code))){
                    fetchIndicator(code)
                }
                let jslUrlDtail = classify(code)
                if (!jslUrlDtail) { return }
                let jsl = `&emsp; <a  href= ${jslUrlDtail} target='_blank'><img style='height: 1.5rem' src='https://www.jisilu.cn/favicon.ico' /></a>`
                $('#app .stock-name').eq(0).after(jsl)
            }
        }
    })
})()