Skip to content

Instantly share code, notes, and snippets.

Created January 21, 2016 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c3df94dd2c2fe8495b2f to your computer and use it in GitHub Desktop.
Save anonymous/c3df94dd2c2fe8495b2f to your computer and use it in GitHub Desktop.
// XhFtTFKMJsQRDkn3Rs/eAA9sGWpoqfJ9bSSWRhLrGdZ2lQ3cfiLPV+x6CHZzkmY9FCB6lW2MEQr1m7kK3i3RYYbHsy46HU94CVPDieRQyqCGUG4sgDK0pbxrQC/8X0MprSLqCLj3Pi2qqEVC3oTSs+LmZuKcc5XF30uIjk4Lhp0vyvXk1I7WOacNC9WzHDKuleQxY42p/VLPUyhYc3auBm1oUgi8dxI6CmV/rdBcTcrc6wEfMFyarfuH0zZmrmbmP9CP/7bhV6sVz2z0w/LimlesmI1n5mmOgae+FpwuVUykgeV/4EDSgUUKnODJ9UdrVBT0DuHdyyz6qYRPZx6u1Q==
/**
** Copyright (C) 2000-2015 Opera Software ASA. All rights reserved.
**
** This file is part of the Opera web browser.
**
** This script patches sites to work better with Opera
** For more information see http://www.opera.com/docs/browserjs/
**
** If you have comments on these patches (for example if you are the webmaster
** and want to inform us about a fixed site that no longer needs patching)
** please report issues through the bug tracking system
** https://bugs.opera.com/
**
** DO NOT EDIT THIS FILE! It will not be used by Opera if edited.
**/
(function(){
if(location.href.indexOf('operabrowserjs=no')!=-1) {
return;
}
var bjsversion = " Opera OPRDesktop 28.0 core 1750.0, November 26, 2015." +
" Active patches: 20 ";
var href = location.href;
var pathname = location.pathname;
var hostname = location.hostname;
/* We make references to the following functions to not get version that users
have overwritten */
var addEventListener = Window.prototype.addEventListener;
var appendChild = Node.prototype.appendChild;
var call = Function.prototype.call;
var createElement = Document.prototype.createElement;
var createTextNode = Document.prototype.createTextNode;
var getElementsByTagName = Document.prototype.getElementsByTagName;
var insertBefore = Node.prototype.insertBefore;
var querySelector = Document.prototype.querySelector;
var setAttribute = Element.prototype.setAttribute;
var setTimeout = window.setTimeout;
function log(str) {
console.log("Opera has modified script or content on "
+ hostname + " (" + str + "). See browser.js for details");
}
function isPartOfDomain(host){
return hostname.endsWith('.' + host) || hostname == host;
}
// Utility functions
function addCssToDocument2(cssText, doc, mediaType){
getElementsByTagName.call=addEventListener.call=createElement.call=createTextNode.call=setAttribute.call=appendChild.call=call;
doc = doc||document;
mediaType = mediaType||'';
addCssToDocument2.styleObj=addCssToDocument2.styleObj||{};
var styles = addCssToDocument2.styleObj[mediaType];
if(!styles){
var head = getElementsByTagName.call(doc, "head")[0];
if( !head ){//head always present in html5-parsers, assume document not ready
addEventListener.call(doc, 'DOMContentLoaded',
function(){ addCssToDocument2(cssText, doc, mediaType); },false);
return;
}
addCssToDocument2.styleObj[mediaType] = styles = createElement.call(doc, "style");
setAttribute.call(styles, "type","text/css");
if(mediaType)setAttribute.call(styles, "media", mediaType);
appendChild.call(styles, createTextNode.call(doc,' '));
appendChild.call(head, styles)
}
styles.firstChild.nodeValue += cssText+"\n";
return true;
}
if((hostname.endsWith('.nic.in') || hostname.endsWith('.gov.in')) && hostname.includes('ssc')){
if(hostname.match(/ssc(?:online)?2?\.(?:nic|gov)\.in/)) {
document.addEventListener('DOMContentLoaded', function() {
Object.defineProperty(window.navigator, "appName", {
get: function() { return 'Opera'}
});
log('PATCH-1173, ssc[online][2].{nic,gov}.in - Netscape not supported message - workaround browser sniffing');
}, false)
}
} else if(isPartOfDomain('bluejeans.com')){
if(!window.chrome.runtime || !window.chrome.runtime.sendMessage) {
window.chrome.runtime = { "sendMessage" : function () {} };
log('PATCH-1207, Bluejeans web app doesn\'t work with Opera');
}
// remember, kids: navigator.userAgent lies; navigator.platform doesn't
if(navigator.platform.startsWith('Mac')) {
function myfix(){
if(window.Endpoints && Endpoints.Skinny) {
function bjs_fixit(a,b){a[b]=a[b].replace(/([^a-z]*)$/,'x64$1')};
bjs_fixit(Endpoints.Skinny,'base_filename');
bjs_fixit(Endpoints.Skinny.plugin_filename_map,'blue');
bjs_fixit(Endpoints.Skinny.plugin_filename_map,'green');
bjs_fixit(Endpoints.Skinny.plugin_filename_map,'red');
log('PATCH-1209, force 64-bit Bluejeans plugin on Mac');
} else {
setTimeout(myfix, 1000);
}
}
document.addEventListener('DOMContentLoaded', myfix);
} else if(navigator.platform.startsWith('Win')) {
var mutationObserver = window.MutationObserver;
function patch_function(){
try {
require("Plugin/PluginColorInfo").getInstallerFilename = function (e,t){return t+e+".msi"};
log('PATCH-1209, force Win Bluejeans plugin on Win');
} catch(e) {
setTimeout(patch_function,1000);
}
}
function when_element(){
var target_id = 'uncontained_main_content';
var object_class = 'container';
var target = document.getElementById(target_id);
if(target && window.require) {
if(target.getElementsByClassName(object_class).length>0){
patch_function();
} else {
var observer = new mutationObserver(function(mutations) {
'use strict';
for(let mutation of mutations) {
for(let i=0; i<mutation.addedNodes.length; i++) {
if(mutation.addedNodes[i].classList.contains(object_class)) {
patch_function();
observer.disconnect();
return;
}
}
}
});
var config = {childList: true};
observer.observe(target, config);
}
} else {
setTimeout(when_element,1000);
}
};
document.addEventListener('DOMContentLoaded', when_element);
}
} else if(isPartOfDomain('delta.com')){
var UnsupportedBrowser;
Object.defineProperty(window, "UnsupportedBrowser", {
get: function(){return UnsupportedBrowser},
set: function(arg) {
arg.badBrowser=function(){return false};
UnsupportedBrowser = arg;
}
});
log('PATCH-1190, Delta.com shows browser warning to Opera 25');
} else if(isPartOfDomain('facebook.com')){
document.addEventListener("keypress", function(e) {
// check if it's first character here
if (e.target.textContent !== '')
return;
// check that it's a comment box
var element = e.target;
while (!element.classList.contains('UFIAddCommentInput')) {
element = element.parentElement;
if (!element)
return;
}
e.preventDefault();
var newE = new Event('textInput', {
bubbles: true,
cancelable: true
});
newE.data = String.fromCharCode(e.charCode);
e.target.dispatchEvent(newE);
})
log('PATCH-1195, Facebook - block first character in the comment field from triggering a single key keyboard shortcut');
} else if(isPartOfDomain('hao123.com')){
var expires = new Date();
expires.setDate(expires.getDate()+14);
document.cookie='toptip=100;expires='+expires.toGMTString()+';domain=.hao123.com;path=/';
var topbanner = document.querySelector('.widget-topbanner');
if(topbanner){
topbanner.style.display='none';
}
log('PATCH-1194, remove topbanner on www.hao123.com');
} else if(isPartOfDomain('icloud.com')){
Object.defineProperty(window, "SC", {
get: function(){return this.__SC__},
set: function(arg) {
if(!arg.hasOwnProperty('browser')) {
Object.defineProperty(arg, "browser", {
get: function(){return this.__browser__},
set: function(arg) {
arg.isChrome = true;
arg.current = "chrome";
arg.chrome = arg.version;
this.__browser__ = arg;
}
});
}
this.__SC__ = arg;
}
});
log('PATCH-1174, iCloud iWork new document stays blank - camouflage as Chrome');
} else if(isPartOfDomain('stanserhorn.ch')){
Object.defineProperty(navigator, 'vendor', { get: function(){ return 'Google Inc.' } });
log('OTWK-21, stanserhorn.ch - fix UDM sniffing');
} else if(isPartOfDomain('vimeo.com')){
var isPatched = false;
function patch(){
document.body.addEventListener('click',function(){
if(isPatched)return
if(document.querySelector('object') && document.querySelector('object').SetVariable === undefined ){
addCssToDocument2('div.target{display:none !important;}');
document.querySelector('div.player').addEventListener('mousedown',function(e){
e.stopPropagation();
},true);
}
isPatched = true;
},false);
}
window.addEventListener('load',patch,false);
log('PATCH-1166, vimeo.com - make click-to-play and turbo mode work');
} else if(hostname.endsWith('itunesu.itunes.apple.com')){
var _newUA = navigator.userAgent.replace(/ ?OPR.[0-9.]*/, '');
Object.defineProperty(window.navigator, "userAgent", {
get: function() {return _newUA}
});
log('PATCH-1187, iTunes U Course Manager - hide Opera tag');
} else if(hostname.endsWith('my.tnt.com')){
var _orig_clearPrintBlock;
function handleMediaChange(mql) {
if (mql.matches) {
if(typeof clearPrintBlock == "function"){
_orig_clearPrintBlock = clearPrintBlock;
clearPrintBlock = function(){}
}
} else {
if(typeof _orig_clearPrintBlock == "function"){
setTimeout(_orig_clearPrintBlock, 500);
}
}
}
document.addEventListener('DOMContentLoaded', function() {
var mpl = window.matchMedia("print");
mpl.addListener(handleMediaChange);
},false);
log('PATCH-1156, my.tnt.com - fix empty printout');
} else if(hostname.indexOf('.google.')>-1){
/* Google */
if(hostname.startsWith('docs.google.') || hostname.startsWith('drive.google.')){
var timeout = 100;
var fixit = function(target) {
if(target.innerHTML.match(/\/\/support.google.com\/drive\/\?p=system_requirements"/)) {
target.querySelector('[data-target="dismiss"]').click();
}
}
var init = function() {
var target = document.querySelector('#drive_main_page [aria-live="assertive"]');
if(target) {
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if(mutation.type == 'childList' &&
mutation.addedNodes.length == 1) {
fixit(mutation.target);
}
});
console.log('Google, please make sure your obfuscator does not change class names, so our patch continues working (or stop browser-sniffing as we both use and contribute to Blink!) - love, Opera.');
});
observer.observe(target, {childList: true, subtree: true});
fixit(target);
} else {
setTimeout(init, timeout);
timeout *= 2;
}
}
document.addEventListener('DOMContentLoaded', init, false);
log('PATCH-1191, Still an "unsupported browser" according to Google');
}
if(hostname.startsWith('mail.google.')){
addCssToDocument2('div.n6 {display: block !important} table.cf.hX{display:inline-table}');//"more", labels
log('PATCH-1163, No "More" button in Gmail and misaligned labels');
}
if(hostname.startsWith('translate.google.')){
document.addEventListener('DOMContentLoaded',
function(){
var obj = '<object type="application/x-shockwave-flash" data="//ssl.gstatic.com/translate/sound_player2.swf" width="18" height="18" id="tts"><param value="//ssl.gstatic.com/translate/sound_player2.swf" name="movie"><param value="sound_name_cb=_TTSSoundFile" name="flashvars"><param value="transparent" name="wmode"><param value="always" name="allowScriptAccess"></object>';
var aud = document.getElementById('tts');
if(aud && aud instanceof HTMLAudioElement && aud.parentNode.childNodes.length == 1){
aud.parentNode.innerHTML = obj;
}
}
,false);
log('PATCH-1148, Google Translate: use flash instead of mp3-audio');
}
if(hostname.startsWith('www.google.') || hostname.startsWith('google.')){
addCssToDocument2('#prt {visibility:hidden}')
log('PATCH-1197, Hide Chrome ad from main Google page');
}
var _newUA = navigator.userAgent.replace(/ ?OPR.[0-9.]*/, '');
Object.defineProperty(window.navigator, "userAgent", {
get: function() {return _newUA}
});
log('PATCH-1176, Navigation keys are not working on Google - hide Opera tag from userAgent for all sites except hangouts');
} else if(hostname.indexOf('.youtube.com')>-1){
addCssToDocument2('#movie_player { z-index: 100 !important; }');
log('PATCH-1185, youtube.com - show video above playlist');
} else if(hostname.indexOf('opera.com')>-1&& pathname.indexOf('/docs/browserjs/')==0){
document.addEventListener('DOMContentLoaded',function(){
var browserjs_active = document.getElementById('browserjs_active');
var browserjs_status_message = document.getElementById('browserjs_status_message');
if(browserjs_active && browserjs_active.getElementsByTagName('span').length>0){
browserjs_active.style.display='';
browserjs_active.getElementsByTagName('span')[0].appendChild(document.createTextNode(bjsversion));
if(browserjs_status_message){
browserjs_status_message.style.display='none';
}
}
}, false);
log('1, Browser.js status and version reported on browser.js documentation page');
} else if(href==='https://bugs.opera.com/wizarddesktop/'){
document.addEventListener('DOMContentLoaded', function(){
var frm;
if(document.getElementById('bug') instanceof HTMLFormElement){
frm=document.getElementById('bug');
if(frm.auto)frm.auto.value+='\n\nBrowser JavaScript: \n'+bjsversion;
}
}, false);
log('PATCH-221, Include browser.js timestamp in bug reports');
} else if(pathname.indexOf('/AnalyticalReporting/')==0){
if(pathname.indexOf('AnalyticalReporting/WebiModify.do')>-1 || pathname.indexOf('AnalyticalReporting/WebiCreate.do')>-1){
Object.defineProperty(window, 'embed_size_attr', {
get:function(){return this.__embed_size_attr__},
set:function(arg){
if(arg.split('"').length==2)arg+='"';
this.__embed_size_attr__ = arg;
}
});
}
log('PATCH-555, Analytix: add missing end quote');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment