Last active
October 19, 2017 02:11
-
-
Save ScottDillman/a0bd3e89d8e05fd5ea3d3a92d55db702 to your computer and use it in GitHub Desktop.
greasemonkey script to get direct link to video on msnbc.com
This file contains 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 fmsnbc | |
// @author ctrauma | |
// @namespace http://dreamcyclestudios.com | |
// @description Create a direct link to MSNBC videos to avoid poor video performance | |
// @twitterURL https://twitter.com/chalktrauma | |
// @homepage http://dreamcyclestudios.com | |
// @license https://creativecommons.org/licenses/by-sa/4.0/ | |
// @updateURL https://gist.github.com/CTrauma/a0bd3e89d8e05fd5ea3d3a92d55db702 | |
// @downloadURL https://gist.github.com/CTrauma/a0bd3e89d8e05fd5ea3d3a92d55db702 | |
// @version 0.1 | |
// @match *://*.msnbc.com/* | |
// @released 2017-10-18 | |
// @updated 2017-10-18 | |
// @compatible Greasemonkey | |
// @icon http://www.dreamcycle.net/favicon.ico | |
// @grant GM_addStyle | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// ==/UserScript== | |
/* | |
* Click video link to launch in new window | |
* or copy and play as a stream in VLC | |
*/ | |
if (typeof jQuery === 'function') { | |
console.log('Running with local copy of jQuery!') | |
GM_main(jQuery) | |
} else { | |
console.log('fetching jQuery from some 3rd-party server.') | |
add_jQuery(GM_main, '3.2.1') | |
} | |
function GM_main ($) { | |
console.log('jQuery is installed with no conflicts! The version is: ' + $.fn.jquery) | |
var results = document.body.innerHTML.match(/(http:[\\/]+link\.theplatform\.com.*?MPEG4)/g) | |
var _highest = 0 | |
gm_jQuery('div').each(function () { | |
var _current = parseInt(gm_jQuery(this).css('zIndex'), 10) | |
if (_current > _highest) { | |
_highest = _current + 1 | |
} | |
}) | |
if (results !== null && typeof (results[0]) !== 'undefined') { | |
console.log('video found!!!') | |
gm_jQuery('body').append('<div style="' + | |
'position: absolute; top: 140px;right: 40px;width:170px;height:50px;' + | |
'-webkit-border-radius: 50px 50px 0px 50px;-moz-border-radius: 50px 50px 0px 50px;' + | |
'border-radius: 50px 50px 0px 50px;border:5px solid #938e83;background:rgba(0,102,204,0.6);"' + | |
'><a target="_BLANK" style="position: relative;' + | |
'float: left;top: 50%;left: 50%;transform: translate(-50%, -50%);color: white;" href="' + results[0] + '"> VIDEO </a></div>') | |
} else { | |
console.log('video not found!!!') | |
gm_jQuery('body').append('<div style="' + | |
'position: absolute; top: 140px;right: 40px;width:170px;height:50px;' + | |
'-webkit-border-radius: 50px 50px 0px 50px;-moz-border-radius: 50px 50px 0px 50px;' + | |
'border-radius: 50px 50px 0px 50px;border:5px solid #938e83;background:rgba(128,0,0,0.6);"' + | |
'><b style="position: relative;' + | |
'float: left;top: 50%;left: 50%;transform: translate(-50%, -50%);color: white;"> VIDEO NOT FOUND </b></div>') | |
} | |
} | |
function add_jQuery (callbackFn, jqVersion) { | |
var jqVersion = jqVersion || '3.2.0' | |
var D = document | |
var targ = D.getElementsByTagName('head')[0] || D.body || D.documentElement | |
var scriptNode = D.createElement('script') | |
scriptNode.src = '//code.jquery.com/jquery-' | |
+ jqVersion | |
+ '.min.js' | |
console.log(scriptNode.src) | |
scriptNode.addEventListener('load', function () { | |
var scriptNode = D.createElement('script') | |
scriptNode.textContent = | |
'var gm_jQuery = jQuery.noConflict (true);\n' | |
+ '(' + callbackFn.toString() + ')(gm_jQuery);' | |
targ.appendChild(scriptNode) | |
}, false) | |
targ.appendChild(scriptNode) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment