User:Gary/stock symbol formatter.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Gary/stock symbol formatter. |
// Generated by CoffeeScript 2.1.1
(function() {
/*
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/
*/
var stockSymbols;
stockSymbols = function() {
var exchanges;
if ((window.mw.util.getParamValue('disable') === 'stocks' || window.mw.config.get('wgCanonicalNamespace') !== '' || window.mw.config.get('wgAction') !== 'view') && window.mw.config.get('wgPageName') !== 'Wikipedia:Sandbox' && window.mw.config.get('wgPageName') !== '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/XNYS:',
// 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
return $('.external').each(function(index, element) {
var exchange, lastCharacter, link, newNode, symbol, url;
link = $(element);
symbol = '';
if (!link.contents().length || !link.contents().eq(0).text()) {
return true;
}
for (exchange in exchanges) {
if (link.attr('href').indexOf(exchanges[exchange]) === -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 = parseInt(lastCharacter) ? exchange.substring(0, exchange.length - 1) + ':' + symbol : exchange + ':' + symbol;
break;
}
if (symbol) {
url = 'http://finance.yahoo.com/q?s=' + symbol;
link.attr('href', url);
newNode = $('<span class="plainlinks"></span>').append(link.clone());
return link.replaceWith(newNode);
}
});
};
$(function() {
return stockSymbols();
});
}).call(this);