User:Gary/stock symbol formatter.coffee
Appearance
STOCK SYMBOL FORMATTER Description: Converts stock symbols links to link to Google Finance. A full list of supported stock exchanges is available here: http://www.google.com/googlefinance/disclaimer/
stockSymbols = ->
if ( window.mw.util.getParamValue('disable') is 'stocks' or window.mw.config.get('wgCanonicalNamespace') isnt or window.mw.config.get('wgAction') isnt 'view' ) and window.mw.config.get('wgPageName') isnt 'Wikipedia:Sandbox' and window.mw.config.get('wgPageName') isnt 'User:Gary_King/Sandbox' return false
# Stock exchanges exchanges = { # Australian Securities Exchange 'ASX': '//www.asx.com.au/asx/research/companyInfo.do?by=asxCode&\ asxCode=' # Stock Exchange of Thailand 'BAK': '//www.set.or.th/set/companyprofile.do?symbol=' # Italy Stock Exchange 'BIT': '//www.borsaitaliana.it/borsa/azioni/scheda/' # Bombay Stock Exchange 'BOM': '//www.bseindia.com/bseplus/StockReach/AdvanceStockReach.aspx?\ scripcode=' # Brazilian Stock Exchange 'BVMF': '//www.bmfbovespa.com.br/cias-listadas/empresas-listadas/' # Euronext 'EBR': '//euronext.com/products/equities/' # Frankfurt Stock Exchange 'ETR': '//www.boerse-frankfurt.de/EN/index.aspx?pageID=23&Query=' # Frankfurt Stock Exchange 'FRA': '//www.boerse-frankfurt.de/en/equities/search/result?\ name_isin_wkn=' # Helsinki Stock Exchange 'HEL': '//www.nasdaqomxnordic.com/shares/shareinformation?\ Instrument=' # Hong Kong Stock Exchange 'HKG': '//www.hkex.com.hk/eng/invest/company/quote_page_e.asp?WidCoID=' # JASDAQ Securities Exchange 'JSD': '//www.ose.or.jp/e/listed_company_info/description/\ company_outline?security_code=' # Johannesburg Stock Exchange 'JSE': 'https://www.jse.co.za/Search?k=' # London Stock Exchange 'LON': '//www.londonstockexchange.com/exchange/searchengine/search.html?q=' # Madrid Stock Exchange 'MCE': '//www.bolsamadrid.es/ing/aspx/Empresas/FichaValor.aspx?ISIN=' # Mutual Funds 'MUTF': '//finance.yahoo.com/q?exchange=MUTF&s=' # Mexican Stock Exchange 'MXK': '//www.bmv.com.mx/wb3/wb/BMV/BMV_busqueda_de_valores/_rid/222/\ _mto/3/_url/BMVAPP/componenteSelectorInput.jsf?cadenaCotizacion=' # NASDAQ 'NASDAQ': '//www.nasdaq.com/symbol/' # National Stock Exchange of India 'NSE': '//www.nseindia.com/marketinfo/companyinfo/companysearch.jsp?\ cons=' # New York Stock Exchange 'NYSE': '//www.nyse.com/quote/XXXX:' # NYSE MKT 'NYSEMKT': 'https://www.nyse.com/quote/XASE:' # New Zealand Stock Exchange 'NZE': '//nzx.com/markets/NZSX/' # OTC Bulletin Board 'OTC1': '//www.otcbb.com/asp/Info_Center.asp?symbol=' # Pink Sheets 'PINK': '//www.otcmarkets.com/stock/' # Philippine Stock Exchange 'PSE': '//www.pse.com.ph/html/MarketInformation/stockinfo.jsp?\ securitySymbol=' # Brazil Stock Exchange 'SAO': '//www.bovespa.com.br/home/ExecutaAcaoCotRapXSL.asp?gstrCA=' # Korea Exchange 'SEO': '//eng.krx.co.kr/mki/stc/stc_d_001.jsp?isu_cd=' # Shanghai Stock Exchange 'SHA': '//www.sse.com.cn/sseportal/webapp/datapresent/\ SSEQueryListCmpAct?' # Taiwan Stock Exchange 'TPE': '//www.twse.com.tw/pdf/en/' # Toronto Stock Exchange 'TSE': '//web.tmxmoney.com/quote.php?qm_symbol=' # Tokyo Stock Exchange 'TYO': '//www2.tse.or.jp/tseHpFront/\ StockSearch.do?callJorEFlg=1&method=&topSearchStr=' # SIX Swiss Exchange 'VTX': '//www.six-swiss-exchange.com/search/quotes_en.html?security=' # Warsaw Stock Exchange 'WSE': '//www.gpw.pl/karta_spolki_en/' }
# Get all elements with "external" class $('.external').each (index, element) -> link = $(element) symbol =
if not link.contents().length or not link.contents().eq(0).text() return true
for exchange of exchanges if link.attr('href').indexOf(exchanges[exchange]) is -1 continue
symbol = link.contents().eq(0).text()
# For OTC exchange only, where last character is an integer lastCharacter = exchange.substr(exchange.length - 1, 1)
symbol = if parseInt(lastCharacter) exchange.substring(0, exchange.length - 1) + ':' + symbol else exchange + ':' + symbol
break
if symbol url = "https://finance.google.com/finance?q=#{symbol}" link.attr('href', url)
newNode = $('').append(link.clone()) link.replaceWith(newNode)
$ ->
stockSymbols()