Created
March 6, 2019 18:11
-
-
Save jabez007/f53442b402c83f479a15f2b3c7865f01 to your computer and use it in GitHub Desktop.
A userscript for StockFlare that shows the individual star ratings for a stock when hovering over the stock ticker in the search results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Stars&Score onHover | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Show the StockFlare stars and StockInvest score onHover | |
// @author jabez007 | |
// @match https://stockflare.com/stocks | |
// @grant none | |
// @require http://code.jquery.com/jquery-3.3.1.min.js | |
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
if (!Array.prototype.last){ | |
Array.prototype.last = function(){ | |
return this[this.length - 1]; | |
}; | |
}; | |
const $div = $(` | |
<div style="background-color: lightblue; padding: 5px; border: 1px solid;"> | |
<div id="Stars-Score-onHover"> | |
{{ message }} | |
</div> | |
</div> | |
`).appendTo('body'); | |
$div.hide(); | |
const app = new Vue({ | |
el: '#Stars-Score-onHover', | |
data: { | |
message: '', | |
}, | |
}); | |
var oldOpen = XMLHttpRequest.prototype.open; | |
function onLoad(event) { | |
$('a').each(function() { | |
const link = this; | |
const $stars = $(link).find('.stars'); | |
$stars.off('mouseenter'); | |
$stars.on('mouseenter', function(e) { | |
const ric = link.href.split('/').last(); | |
const ticker = ric.split('.')[0]; | |
$.ajax({ | |
method: 'PUT', | |
url: 'https://api.stockflare.com/search/filter', | |
data: `{ "conditions": { "ticker": "${ticker}" }, "select": ["sic", "ric"] }`, | |
success: function(data) { | |
const sic = (data.find(stock => stock.ric === ric) || {}).sic; | |
if (sic){ | |
$.ajax({ | |
method: 'PUT', | |
url: 'https://api.stockflare.com/latest', | |
data: `{ "select": ["_all"], "sic": "${sic}" }`, | |
success: function(data) { | |
app.$data.message = JSON.stringify(data); | |
} | |
}) | |
} | |
} | |
}); | |
$div.css({'top':e.pageY+50,'left':e.pageX, 'position':'absolute'}); | |
$div.show(); | |
}); | |
$stars.off('mouseleave'); | |
$stars.on('mouseleave', function(){ | |
app.$data.message = ''; | |
$div.hide(); | |
}); | |
}); | |
}; | |
XMLHttpRequest.prototype.open = function() { | |
// when an XHR object is opened, add a listener for its load events | |
this.addEventListener("load", onLoad); | |
// run the real `open` | |
oldOpen.apply(this, arguments); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/Stockflare/notes-on-api