// ==UserScript== // @name PPCG Graduation Script // @namespace https://github.com/vihanb/PPCG-Design // @version 4.0.10 // @description A script to self-graduate PPCG // @match *://*.codegolf.stackexchange.com/* // @match *://codegolf.meta.stackexchange.com/* // @match *://chat.stackexchange.com/* // @author PPCG Community // @grant GM_getValue // @grant GM_setValue // @grant GM_listValues // @grant GM_deleteValue // @require https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js // @updateURL https://rawgit.com/vihanb/PPCG-Design/master/ppcg.user.js // ==/UserScript== //////////////////////////////////////////////////////////////////////// ////////////////////// ////////////////////////// ////////////////////// GLOBAL VARIABLES ////////////////////////// ////////////////////// ////////////////////////// //////////////////////////////////////////////////////////////////////// var site = window.location.hostname; // main, meta, or chat if (/meta/.test(site)) site = 'meta'; else if (/chat/.test(site)) site = 'chat'; else site = 'main'; $('[rel="shortcut icon"][href^="//cdn.sstatic.net/Sites/codegolf/img/favicon.ico"]').attr('href', 'https://i.stack.imgur.com/oHkfe.png'); $('img[src^="//cdn.sstatic.net/Sites/codegolf/img/favicon.ico"]').attr('src', 'https://i.stack.imgur.com/oHkfe.png'); var isNotPPCGChat = (site === 'chat' && !$('[rel="shortcut icon"]')[0].href.startsWith('https://i.stack.imgur.com/oHkfe.png')); function style (html) { var style = document.createElement('style'); style.innerHTML = html; document.head.appendChild(style); } // ['Propose', 'Porpoise'], // >:D var reps = [ ['Helka Homba', 'Calvin\'s Hobbies'], ['HelkaHomba', 'CalvinsHobbies'], ['Helka', 'Calvin'], ['fItaJ.png', 'qkXJy.png'], ['Aqua Tart', 'quartata'], ['Don Musolini', 'Luis Mendo'], ['DonMusolini', 'LuisMendo'], ['AandN', 'Adnan'], ['A and N', 'Adnan'], ['lirtosiast', 'Thomas Kwa'], ['I Go Best', 'Geobits'], ['IGoBest', 'Geobits'], //['Code Review', 'the evil code reviewers'] ihaichu - EasterlyIrk on behalf of CR. ]; var rReps = new RegExp(reps.map(function (arr) { return arr[0].replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); }).join(''), 'g'); var repMap = new Map(reps); /* These are the alternating tag choices for the QOD widget */ var QOD_ALTERNATING_TAGS = ['string', 'popularity-contest', 'ascii-art', 'number', 'kolmogorov-complexity', 'graphical-output', 'king-of-the-hill', 'fastest-code', 'restricted-source', 'arithmetic', 'sequence', 'game', 'tips', 'geometry', 'number-theory', 'random', 'primes', 'array-manipulation', 'date', 'image-processing', 'graphs', 'sorting', 'interpreter', 'optimization', 'parsing', 'path-finding', 'puzzle-solver', 'underhanded', 'source-layout', 'base-conversion' ]; if (site === 'chat' && (GM_getValue('main.RUN_IN_CHAT') !== true)) throw 'Not executing script'; // Fonts var HEADER_FONT = 'Lato, "Open Sans", Arial, sans-serif'; // Header text var TEXT_FONT = '"Open Sans", Lato, "Helvetica Neue", Arial, sans-serif'; // Everything else besides code var MONOSPACE_FONT = 'Inconsolata, monospace'; // Monospace font & Tag font var FONT_URL = '//fonts.googleapis.com/css?family=Lato:700|Open+Sans|Inconsolata'; // import any webfonts here // Colors var MOD_FLAIR = '#F0C800'; // Mod diamond var MOD_FLAIR_HOVER = '#FFE32E'; /** ~~~~~~~~~~~~~~~~ MAIN SITE CUSTOMIZABLE PROPERTIES ~~~~~~~~~~~~~~~~ **/ var main = { FAVICON: '//i.stack.imgur.com/oHkfe.png', DISP_ICON: '//i.stack.imgur.com/oHkfe.png', SPRITE_SHEET: '//cdn.rawgit.com/vihanb/PPCG-Design/master/assets/sprites.svg', SEARCH_TEXT: 'Search codegolf.SE', // Set to empty string for no background image BACKGROUND_IMAGE: '//i.stack.imgur.com/4Y7TE.png', PAGE404: '//i.stack.imgur.com/ToEtE.png', BG_COL: '#175D2E', BG_COL_HOVER: 'white', BG_START: 'white', BG_REV: '#329300', CTA_BG: '#3C9331', CTA_FG: 'white', GOAT_MODE: (GM_getValue('main.GOAT_MODE') === true), // default false BACKGROUND_LIGHT: (GM_getValue('main.BACKGROUND_LIGHT') === true), // Lighter shade of the background, CHANGE THROUGH OPTIONS MODE_DARK: (GM_getValue('main.MODE_DARK') === true), RUN_IN_CHAT: (GM_getValue('main.RUN_IN_CHAT') !== false), PREFER_LIGHT_FONT: (GM_getValue('main.PREFER_LIGHT_FONT') === true), USE_LEADERBOARD: (GM_getValue('main.USE_LEADERBOARD') !== false), // default is true SHOW_QOD_WIDGET: (GM_getValue('main.SHOW_QOD_WIDGET') !== false), // default is true USE_AUTOTIO: (GM_getValue('main.USE_AUTOTIO') !== false), // default is true PROPOSE: GM_getValue('main.PROPOSE') || 'Propose', REPLACE_NAMES: GM_getValue('main.REPLACE_NAMES') === true, // default is false SHOW_BYTE_COUNTS: GM_getValue('main.SHOW_BYTE_COUNTS') !== false, // default is true // You can use RGB, hex, or color names BACKGROUND_COLOR: '#FAFAFA', HEADER_BG_COLOR: 'transparent', HEADER_BG_IMAGE: '', HEADER_TEXT_COLOR: '#FFF', CURR_TAB_COLOR: '#62BA15', BULLETIN_BG_COLOR: '#fff8dc', STATS_COLOR: '#FAFAFA', LINK_COLOR: 'rgb(60, 100, 60)', VISITED_LINK_COLOR: 'rgb(30,50,30)', HOVER_LINK_COLOR: 'rgb(45,75,45)', POST_QUESTION_COLOR: 'rgba(140,180,140,0.75)', POST_QUESTION_CORNER_RADIUS: '5px', TEXT_COLOR: 'black', CODE_COLOR: 'black', CODE_BACKGROUND: '#EEE', TOPBAR: 'rgba(12, 13, 14, .86)', LABEL_KEY: '#9199A1', LABEL_KEY_B: '#3B4045', MODULE_H4: '#3B4045', HYPERLINK: '#4E82C2', HYPERLINK_VISITED: '#18529A', POST_HYPERLINK: '#4E82C2', POST_HYPERLINK_VISITED: '#18529A', QUESTION_STATUS: '#FFF7E5', OWNER: '#E1ECF9', USER_INFO: '#848D95', TAG_COLOR: '#D4F493', TAG_HOVER: '#329300', TAG_SHADOW_COLOR: '#BACD56', TAG_HOVER_SHADOW_COLOR: '#256C00', BUTTON_COLOR: '#6DAB71', BUTTON_HOVER: '#5DA261', // Specify nothing to make these default color BOUNTY_COLOR: 'rgb(72,125,75)', BOUNTY_BG_COLOR: 'rgb(172,225,175)', BOUNTY_INDICATOR: '#6DAB71', // QOD Settings QOD_NUMBER_OF_QS_SHOWN: GM_getValue('QOD_NUMBER_OF_QS_SHOWN') || 5, QOD_ALWAYS_SHOWN_TAGS: JSON.parse(GM_getValue('QOD_ALWAYS_SHOWN_TAGS') || 0) || ['code-golf', 'code-challenge', 'math'] }; /** ~~~~~~~~~~~~~~~~ META SITE CUSTOMIZABLE PROPERTIES ~~~~~~~~~~~~~~~~ **/ var meta = { FAVICON: '//i.imgur.com/xJx4Jdd.png', DISP_ICON: '//i.stack.imgur.com/dY4TQ.png', SPRITE_SHEET: '//cdn.rawgit.com/vihanb/PPCG-Design/master/assets/sprites.svg', SEARCH_TEXT: 'Search codegolf.meta.SE', // Set to empty string for no background image BACKGROUND_IMAGE: '//i.stack.imgur.com/4535h.png', PAGE404: '', BG_COL: '#474747', BG_COL_HOVER: '#474747', BG_START: 'rgba(255, 255, 255, 0.8)', BG_REV: 'white', CTA_BG: '#E4E6E8', CTA_FG: 'black', // You can use RGB, hex, or color names BACKGROUND_COLOR: '#FAFAFA', HEADER_BG_COLOR: 'transparent', HEADER_TEXT_COLOR: '#FFF', CURR_TAB_COLOR: 'rgb(72,125,75)', BULLETIN_BG_COLOR: '#fff8dc', STATS_COLOR: '#FCFCFC', // Content BG TAG_COLOR: '', TAG_BORDER_COLOR: '', BUTTON_COLOR: '#303030', POST_QUESTION_COLOR: 'rgba(255, 255, 255, 0.75)', POST_QUESTION_CORNER_RADIUS: '5px', TEXT_COLOR: 'black', CODE_COLOR: 'black', CODE_BACKGROUND: '#EEE', TOPBAR: 'rgba(12, 13, 14, .86)', LABEL_KEY: '#9199A1', LABEL_KEY_B: '#3B4045', MODULE_H4: '#3B4045', HYPERLINK: '#4E82C2', HYPERLINK_VISITED: '#18529A', POST_HYPERLINK: '#4E82C2', POST_HYPERLINK_VISITED: '#18529A', QUESTION_STATUS: '#FFF7E5', OWNER: '#E1ECF9', USER_INFO: '#848D95', // Specify nothing to make these default color BOUNTY_COLOR: 'rgb(72,125,75)', BOUNTY_BG_COLOR: 'rgb(172,225,175)', BOUNTY_INDICATOR: '#6DAB71' }; var darktheme = { BACKGROUND_COLOR: 'red', BACKGROUND_IMAGE: '//i.stack.imgur.com/vAWfF.png', STATS_COLOR: '#364', BULLETIN_TITLE: '#000000', BULLETIN_BG_COLOR: 'rgb(136,170,131)', META_LINK_COLOR: 'rgb(34,36,38)', POST_QUESTION_COLOR: 'rgba(134,180,140,0.75)', POST_QUESTION_RADIUS: '5px', LINK_COLOR: 'rgb(160, 213, 162)', VISITED_LINK_COLOR: 'rgb(110,150,110)', RIGHTBAR_BG: '#B0D4AB', RIGHTBAR_BORDER: 'none', TEXT_COLOR: '#D6ECCB', CODE_COLOR: '#BDB', CODE_BACKGROUND: '#264730', TOPBAR: 'rgba(45, 64, 46, .86)', LABEL_KEY: '#8FAF8E', LABEL_KEY_B: '#B7D4A8', MODULE_H4: '#B7D4A8', HYPERLINK: '#6EC171', HYPERLINK_VISITED: '#6EC171', POST_HYPERLINK: '#6EC171', POST_HYPERLINK_VISITED: '#6EC171', QUESTION_STATUS: '#6B7D5A', OWNER: '#609C86', USER_INFO: '#B8C4CE' }; var metadark = { STATS_COLOR: '#555', BULLETIN_TITLE: '#000000', BULLETIN_BG_COLOR: '#AAA', META_LINK_COLOR: 'rgb(34,36,38)', POST_QUESTION_COLOR: 'rgba(150,150,150,0.75)', POST_QUESTION_RADIUS: '5px', LINK_COLOR: '#DDD', VISITED_LINK_COLOR: '#BBB', HOVER_LINK_COLOR: '#CCC', RIGHTBAR_BG: '#B0D4AB', RIGHTBAR_BORDER: 'none', TEXT_COLOR: '#DDD', CODE_COLOR: '#CCC', CODE_BACKGROUND: '#222', TOPBAR: 'rgba(12, 13, 14, .86)', LABEL_KEY: '#9199A1', LABEL_KEY_B: '#C1C1C1', MODULE_H4: '#9199A1', HYPERLINK: '#4E82C2', HYPERLINK_VISITED: '#99B4D6', POST_HYPERLINK: '#4E82C2', POST_HYPERLINK_VISITED: '#18529A', QUESTION_STATUS: '#FFF7E5', OWNER: '#E1ECF9', USER_INFO: '#848D95' }; var lightbg = { BACKGROUND_COLOR: 'red', BACKGROUND_IMAGE: '//i.stack.imgur.com/t8GhU.png' }; var optionbox = { // Customizes option box BACKGROUND_TINT: 'linear-gradient(rgba(69, 174, 103, 0.57), rgba(73, 166, 83, 0.47))', BACKGROUND_COLOR: '#FAFAFA' }; var BGHEIGHT = 0; // this + 130 var PARSE_CODEBLOCKS = main.SHOW_BYTE_COUNTS; // set to false to not parse code block lengths var PARSE_HEXDUMPS = main.SHOW_BYTE_COUNTS; // set to false to not parse hexdump lengths if (GM_getValue('main.MODE_DARK') === true) { main = $.extend(main, darktheme); meta = $.extend(meta, metadark); } if (GM_getValue('main.BACKGROUND_LIGHT') === true) { main = $.extend(main, lightbg); document.body.style.backgroundRepeat = "repeat"; } /** ~~~~~~~~~~~~~~~~ END CSS PROPERTIES ~~~~~~~~~~~~~~~~ **/ // apply goat mode if (main.GOAT_MODE) { $('head').append($('', { html: '.vote-up-off {' + ' background-image: url(https://cdn.rawgit.com/vihanb/PPCG-Design/master/assets/upgoat-off.svg) !important;' + ' background-size: 100% !important;' + ' background-position: 0px 0px;' + '}' + '.vote-down-off {' + ' background-image: url(https://cdn.rawgit.com/vihanb/PPCG-Design/master/assets/downgoat-off.svg) !important;' + ' background-size: 100% !important;' + ' background-position: 0px 0px;' + '}' + '.vote-up-on {' + ' background-image: url(https://cdn.rawgit.com/vihanb/PPCG-Design/master/assets/upgoat.svg) !important;' + ' background-size: 100% !important;' + ' background-position: 0px 0px;' + '}' + '.vote-down-on {' + ' background-image: url(https://cdn.rawgit.com/vihanb/PPCG-Design/master/assets/downgoat.svg) !important;' + ' background-size: 100% !important;' + ' background-position: 0px 0px;' + '}' })); } // What does this do?? var match = $('link[href="//cdn.sstatic.net/codegolf/img/favicon.ico?v=cf"]').attr('href', main.FAVICON); if (match.length > 0) { $('#input-area').css('background', 'url(' + 'https://i.stack.imgur.com/oqoGQ.png' + ')'); $('#input-area').css('background-size', '600px 400px'); if (GM_getValue('main.MODE_DARK') == 'true') $('#input-area').css('background', 'url(' + darktheme.BACKGROUND_IMAGE + ')'); if (GM_getValue('main.BACKGROUND_LIGHT') == 'true') $('#input-area').css('background', 'url(' + lightbg.BACKGROUND_IMAGE + ')'); style(('a.post-tag{border-radius: 0;text-align:center;font-family:' + MONOSPACE_FONT + ';font-size:12px;white-space: nowrap;background-color:$$TAG_COLOR;border:none; -webkit-transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease; -moz-transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease; -ms-transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease; -o-transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease; border-bottom: 2px solid $$TAG_SHADOW_COLOR}' + 'a.post-tag:hover{border-bottom-color: $$TAG_HOVER_SHADOW_COLOR;background: $$TAG_HOVER; color: white}').replace(/\$\$(\w+)/g, function (_, m) { return main[m]; })); } //////////////////////////////////////////////////////////// ////////////////// CHAT STYLES ////////////////////// //////////////////////////////////////////////////////////// if (site === 'chat') { $('body').css('background', 'white'); $('#sound').css({ 'background': 'url(https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Speaker_Icon.svg/200px-Speaker_Icon.svg.png)', 'background-size': '16px 16px' }); $('#roomname').css('font-family', '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif'); $('#roomname').css('font-weight', '400'); $('#searchbox').css('padding-left', '4px !important'); if (!isNotPPCGChat) { // PPCG-chat specific styling $('#footer-logo a').text('Programming Puzzles & Code Golf').css('color', '#2A2'); $('#input-area').css('background', 'url(' + main.BACKGROUND_IMAGE + ')'); } $("#chat").prepend($('
').css({ 'position': 'absolute', 'left': '16%', 'top': '0', 'bottom': '120px', 'width': '1px', 'background': '#EEE', 'z-index': '0' })); if (main.PREFER_LIGHT_FONT) { style( 'div.message { font-weight: 300 }' + 'div.message a { font-weight: 600 }' ); } style('@import url(https://fonts.googleapis.com/css?family=Lato:400,700,400italic|Open+Sans:400,400italic,700,700italic&subset=latin,greek);' + 'body { font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif; font-size: 13px; }' + '#roomtitle { margin: 10px 0; margin-bottom: 5px; }' + '#roomdesc { font-size: 0.9em; }' + '#sidebar #info #sidebar-menu, #present-users, ul#my-rooms { border-bottom: none }' + 'pre.prettyprint { border: none !important; padding: 1em 1.2em !important; background: #FAFAFA; border-radius: 8px; }' + '.button { cursor: pointer; background: #96db62; border: none; border-bottom: 1px solid rgb(106, 194, 65) }' + '.button:hover { background: #51cc47; border-bottom-color: #449656; }' + '.favorite-room-vote { background: url(https://i.stack.imgur.com/DhUx0.png); background-size: 16px 16px }' + '.favorite-room-vote.favorite-room { background: url(https://i.stack.imgur.com/lbBdl.png); background-size: 16px 16px }' + '.ob-post-tag { background: rgba(255, 255, 255, 0.8) !important; padding: 4px 8px !important; border-radius: 4px !important; border: none !important; box-shadow: 0 0 1px #AAA !important; color: inherit !important }' + '.ob-post-tag:hover { background: rgba(255, 255, 255, 0.6) !important }' + 'a:hover { color: #448be0; text-decoration: none }' + '.user-container img { border-radius: 2px }' + '.username.owner, .monologue .tiny-signature .username { margin-top: 0; font-size: 0.9em; line-height: 1.6em; overflow: visible; height: auto; }' + '.quote { border-left: 3px solid rgba(0, 0, 0, 0.2); padding-left: 8px; margin-left: 6px; }' + 'div.message code { padding: 2px 5px; border-radius: 3px; background: rgba(0, 0, 0, 0.06); }' + '#tabcomplete li { padding: 5px; border-radius: 5px; border: none }' + 'div.message.reply-parent, div.message.reply-child { background-color: #EEE; }' + '.message { color: rgba(0, 0, 0, 0.7); border: none; }' + '.message:hover { border: 1px solid #F3F3F3 !important }' + '.message:hover .action-link, .message:hover .action-link .img.menu { background-color: #F3F3F3 !important }' + '.message:hover .action-link .img.menu { background-image: url(https://i.stack.imgur.com/3gBKh.png) !important; background-size: 16px 16px; background-position: 0px -1px !important; }' + '.vote-count-container.stars .img { background-image: url(https://i.stack.imgur.com/DhUx0.png) !important; background-size: 10px 10px; background-position: initial !important; }' + '.vote-count-container.stars.user-star .img { background-image: url(https://i.stack.imgur.com/lbBdl.png) !important; }' + '.monologue { margin-bottom: 0; padding-top: 0; }' + '.monologue .signature { width: 15%; margin-top: 8px; margin-bottom: 8px; }' + '.monologue:first-child .messages { border-top: 1px solid #F2F2F2 }' + '.messages, .mine .messages { background-color: #FFF; padding: 8px 8px 8px 0px; border-radius: 0; border: none }' + '.mine .messages { background-color: rgba(210, 245, 255, 0.50); }' + '.catchup-marker .messages { border: none !important }' + '.messages { width: 82%; }' + '.system-message-container { margin: 1em 0; }' + '.system-message { position: relative; z-index: 1; }' + '.system-message:after { content: \'\'; position: absolute; z-index: -1; top: 0; bottom: 0; left: 8px; right: 0px; border-radius: 6px; background: #f8f8f8; }' + '.catchup-marker { border: none !important; margin-top: 10px }' + '.catchup-marker .messages { border-top: 1px solid #F2F2F2; }' + '.popup { border-radius: 2px; border: none; box-shadow: 0 0 8px #DDD }' + '.popup .small-site-logo { right: initial; top: 38px }' + '#footer-legal a { color: #366fb3 !important }' + '#sidebar { background: #fbfbfb; box-shadow: 5px 0px 5px -3px #EEE inset; padding-left: 3px } ' + 'input[type=text], #input, #chat-body input#searchbox { border-radius: 2px; border: 1px solid #c2c2c2; padding: 3px 2px !important; box-shadow: none; outline: none; -webkit-transition: box-shadow 0.30s ease-in-out; -moz-transition: box-shadow 0.30s ease-in-out; -ms-transition: box-shadow 0.30s ease-in-out; -o-transition: box-shadow 0.30s ease-in-out; transition: box-shadow 0.30s ease-in-out }' + 'input[type=text]:focus, #input:focus, #chat-body input#searchbox:focus { outline: none; box-shadow: 0px 0px 4px #3AE; border: 1px solid #70d2ff; }' + '#input:hover { box-shadow: 0px 0px 6px #50c8ff; }' + 'span.mention { padding: 3px 6px; border-radius: 5px; background: #D2FFCC !important }' ); } ////////////////////////////////////////////////////////// /////////////// END CHAT STYLES //////////////////// ////////////////////////////////////////////////////////// // what is this for? //x=document.getElementsByClassName('community-bulletin')[0].getElementsByClassName('question-hyperlink') //for (var i=0;i| | ).+?(-?\b\d+(?:\.\d+)?)\s*(?:bytes?|chars?|char[ea]ct[ea]?rs?)/i) || [])[1] ||
(i.body.match(/^\s*(?: ).*?(-?\d+(?:\.\d+)?)\D*?<\/(?:h\d|strong)>/i) || [])[1]
);
i.body = i.body.replace(RegExp(',?\\s*' + j + '.*'), '');
// Taken (and modified) from https://codegolf.stackexchange.com/a/69936/40695
var e = (header || 'Unknown Language')
.replace(/<.*?>/g, '')
.replace(/ in .+$/g, '')
.replace(/([\–\|\/\-:\—,]?\s*\d+\s*(b[l]?y[te]{2}s?|Lab ?View|char[a-z]*|codels?)\s*)+/g, '')
.replace(/^([A-Za-z]+)\s*(?:,?\s*\d{2,}\s*|,\s*)$/, '$1')
.replace(/(,| [-&(–—5]| [0-7]\d)(?! W|...\)).*/g, '')
.replace(/2 |:/g, '')
.replace(/(Ver(sion)?.?\s*)\d{2,}w\d{2,}a/g, '');
return [j, i, copyvalue, e];
});
var lv = 0;
answers = answers.filter(function (a) {
return !isNaN(a[0]);
}).sort(function (a, b) {
return a[0] - b[0];
});
var generatedanswertable = answers.map(function (l, i, a) {
if ((a[i - 1] || [NaN])[0] !== l[0]) lv = (i || 0) + 1;
return ' )(.+?)[, -]\s*(?:(?:\d*\.\d+|\d+)(?:\s*%)?(?:\s*[+*\/\-]\s*(?:\d*\.\d+|\d+)(?:\s*%)?)+\s*=\s*)?(?:-?\b\d+(?:\.\d+)?)\s*(?:bytes?|chars?|char[ea]ct[ea]?rs?)/)||[])[1]||(l[2].match(/\s*(?: ';
});
var tryitonlineattempt = $(answers[0][2]).find('a[href*=".tryitonline.net"]').attr('href');
$('#answers').prepend('' + lv + ' ' + l[1].owner.display_name + ' ' + (l[3] /*(l[2].match(/(?: ' + l[0] + ' bytes Link
';
}
}
function applyCss() {
console.log('applying the css', siteProperties);
if (main.PREFER_LIGHT_FONT) {
style(
'html, body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; }' +
'.post-text h1, .post-text h2, .post-text h3, .post-text h4, .post-text h5, .post-text h6 { color: black; }' +
'#mainbar { color: rgba(19, 29, 40, 0.87) }' +
'#mainbar { font-weight: 300 }' +
'#mainbar a { font-weight: 400; color: #5d95d9 }'
);
}
style('.site-header .site-header--container { justify-content: start; } .site-header .site-header--link { margin-left: 16px !important }');
$('.site-header--container').prepend('');
// MAIN STYLES FOR PAGE
$('#mainbar').css('padding', '15px');
style((
(main.PREFER_LIGHT_FONT ? "" : '@import url(' + FONT_URL + ');') +
'.site-header { background-image: url($$BACKGROUND_IMAGE); background-size: 50%; height: 100px; display: flex; align-items: center; }' +
'.site-footer, .js-footer, #footer { background-image: url($$BACKGROUND_IMAGE); background-size: 50%; background-repeat: repeat; }' +
'body{color: $$TEXT_COLOR}' +
'code,pre{color:$$CODE_COLOR;background-color:$$CODE_BACKGROUND}' +
'.topbar{background:$$TOPBAR}' +
'.label-key{color:$$LABEL_KEY}' +
'.label-key b,.label-key strong{color:$$LABEL_KEY_B}' +
'.module h4{color:$$MODULE_H4}' +
'.owner{background:$$OWNER}' +
'.user-info{color:$$USER_INFO}' +
'.question-status{background:$$QUESTION_STATUS}' +
'.question-hyperlink,.answer-hyperlink,#hot-network-questions ul a{color:$$HYPERLINK}' +
'.question-hyperlink:visited,.answer-hyperlink:visited,#hot-network-questions ul a:visited{color:$$HYPERLINK_VISITED}' +
'.post-text a,.comment-text a:not(.comment-user){color:$$POST_HYPERLINK}' +
'.post-text a:visited,.comment-text a:not(.comment-user):visited{color:$$POST_HYPERLINK_VISITED}' +
'.envelope-on,.envelope-off,.vote-up-off,.vote-up-on,.vote-down-off,.vote-down-on,.star-on,.star-off,.edited-yes,.feed-icon,.vote-accepted-off,.vote-accepted-on,.vote-accepted-bounty,.badge-earned-check,.delete-tag,.grippie,.expander-arrow-hide,.expander-arrow-show,.expander-arrow-small-hide,.expander-arrow-small-show,.anonymous-gravatar,.badge1,.badge2,.badge3,.gp-share,.fb-share,.twitter-share,#notify-containerspan.notify-close,.migrated.to,.migrated.from{background-image:url(\'$$SPRITE_SHEET\');background-size: initial;}' +
'.vote-up-on, .vote-up-off, .vote-down-on, .vote-down-off, .star-off, .star-on { height: 40px; }' +
'.vote-up-on, .vote-up-off { background-position-y: -173px; }' +
'.vote-down-on, .vote-down-off { background-position-y: -224px; }' +
'.vote-up-on, .vote-down-on { filter: none; -webkit-filter: none; -moz-filter: none; -ms-filter: none; }' +
'.youarehere{color:$$CURR_TAB_COLOR !important;border-bottom:2px solid $$CURR_TAB_COLOR !important;}' +
'#sidebar #beta-stats, #sidebar #promo-box{background:$$RIGHTBAR_BG;border:$$RIGHTBAR_BORDER}' +
(siteProperties.BOUNTY_COLOR ? '.bounty-indicator-tab{background:$$BOUNTY_BG_COLOR;color:$$BOUNTY_COLOR !important;}' : '') +
'#sidebar .module.community-bulletin{background:$$BULLETIN_BG_COLOR;}' +
'.bulletin-title{color:$$BULLETIN_TITLE;}' +
'div.module.newuser,#promo-box{border-color:#e0dcbf;border-style:solid;border-width:1px;}' +
'.yes-hover{cursor:pointer !important;}' +
'.qod-item { display: table }' +
'.qod-item > *{ display: table-cell; vertical-align:middle }' +
'.qod-item > *:not(.post-tag) { font-weight: normal; font-size: 12px; white-space: normal; padding-left: 5px; }' +
'.qod-item:not(:first-child) { margin-top: 5px; }' +
'.LEADERBOARD {border-collapse: collapse} .LEADERBOARD td { padding: 6px 8px } .LEADERBOARD tr:nth-child(even) { background-color: #F1F1F1 } .LEADERBOARD thead { border-bottom: 1px solid #DDD }' +
(main.PREFER_LIGHT_FONT ? "" : 'html,body{font-family:' + TEXT_FONT + '}') +
'a.badge { color: white !important }' +
'#content{margin-top: 7px;}' +
'#footer #footer-sites a, #footer th {color: #BFBFBF;}' +
'.container{box-shadow: none !important;}' +
'.nav.askquestion li { display: block !important; }' +
'body,#content{background:$$STATS_COLOR !important;}' +
'#hmenus > div.nav:not(.mainnavs) a{text-align:center; color: $$BG_COL;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;background: $$BG_START;padding: 8px 12px;-webkit-transition: color 0.15s ease, background 0.15s ease;-moz-transition: color 0.15s ease, background 0.15s ease;-ms-transition: color 0.15s ease, background 0.15s ease;-o-transition: color 0.15s ease, background 0.15s ease;}' +
'#hmenus > div.nav:not(.mainnavs) a:hover{color: $$BG_COL_HOVER;background: $$BG_REV;}' +
'#sidebar > .module{margin-left: 12px;}' +
'input[type=submit], input[type=button], button, .button, a.button, a.button:visited, .btn { box-shadow: none; border: 1px solid $$BUTTON_COLOR; background-color: $$BUTTON_COLOR }' +
'.module.community-bulletin{border: none}' +
'input[type=submit]:hover, input[type=button]:hover, button:hover, .button:hover, a.button:hover, a.button:visited:hover, .btn:hover,' +
'input[type=submit]:focus, input[type=button]:focus, button:focus, .button:focus, a.button:focus, a.button:visited:focus, .btn:focus{ box-shadow: none; border: 1px solid $$BUTTON_HOVER; background-color: $$BUTTON_HOVER }' +
'.mod-flair,.started .mod-flair{ color: ' + MOD_FLAIR + ' !important }.mod-flair:hover,.started .mod-flair:hover{color:' + MOD_FLAIR_HOVER + '}' +
'#hmenus > div.nav.mainnavs{position: relative; top: 50%; -ms-transform: translateY(-50%);-webkit-transform: translateY(-50%);-moz-transform: translateY(-50%);-o-transform: translateY(-50%); transform: translateY(-50%);}' +
'div.nav.askquestion li{display:initial;}' +
'#hmenus{top: 50%;-ms-transform: translateY(-50%);-webkit-transform: translateY(-50%);-moz-transform: translateY(-50%);-o-transform: translateY(-50%);transform: translateY(-50%);}' +
'#hmenus > div.nav.askquestion li:not(:first-child) > a { margin-top: 5px; }' +
'#hmenus > div.nav:not(.mainnavs) a{border-radius: $$POST_QUESTION_RADIUS;background:$$POST_QUESTION_COLOR}' +
'.site-header .site-header--link {color:$$HEADER_TEXT_COLOR;}' +
'a.post-tag{border-radius: 0;text-align:center;font-family:' + MONOSPACE_FONT + ';font-size:12px;white-space: nowrap;background-color:$$TAG_COLOR;border:none; -webkit-transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease; -moz-transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease; -ms-transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease; -o-transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease; border-bottom: 2px solid $$TAG_SHADOW_COLOR}' +
'a.post-tag:hover{border-bottom-color: $$TAG_HOVER_SHADOW_COLOR;background: $$TAG_HOVER; color: white}' +
'div.module.newuser,div.module.community-bulletin,div.categories{background-color:$$BACKGROUND_COLOR;}' +
'#newlogo{top:-15px;position:relative;}#newlogo td{padding-right:15px;}#newlogo td:nth-child(2){vertical-align:middle;}#hlogo a{width:600px;}' +
'.top-footer-links a {text-shadow: 1px 1px white;}' +
'#footer a { text-shadow: none; color: #78ee74 !important }' +
'#footer a:visited { color: #78ff74 !important }' +
'.site-header .site-header--link, .fs-headline1 {font-family:' + HEADER_FONT + ';}' +
'.fs-headline1 { font-weight: bold; }' +
'#question-of-the-day-content {padding: 5px;border: 3px solid #d4f493;}' +
'#question-of-the-day h4 {font-weight: 700;}' +
'#sidebar > .module {margin-left: 0;}' +
'#tabs > a { background: transparent }' +
'#tabs > a.youarehere { border-top: none; border-left: none; border-right: none; }' +
'#tabs > a.youarehere:before { background-color: transparent; }' +
'.tabs-filter .youarehere { background: transparent !important; border-top-color: #adb3b9 !important; border-right-color: #adb3b9 !important; border-left-color: #adb3b9 !important; }' +
'.nav-links .youarehere a { border-right: none !important; letter-spacing: -.6px; }' +
'.s-btn.s-btn__primary { background: $$CTA_BG !important; box-shadow: 0px 4px 8px -4px rgba(0, 0, 0, 0.1); color: $$CTA_FG; border: none; }' +
// fix some links
'#tabs a:hover, .tabs a:hover, .newnav .tabs-list-container .tabs-list .intellitab a:hover {' +
'color:#5DA261;' +
'border-bottom:2px solid #5DA261' +
'}' +
'a {' +
'color:$$LINK_COLOR}' +
'a:visited {' +
'color:$$VISITED_LINK_COLOR}' +
'a:hover {' +
'color:$$HOVER_LINK_COLOR}').replace(/\$\$(\w+)/g, function (_, x) {
console.log('got to', x);
return eval(site + '.' + x);
}));
}
function replaceNames() {
//from https://j11y.io/javascript/replacing-text-in-the-dom-its-not-that-simple/
$('p').each(function (){
traverseChildNodes(this);
});
function traverseChildNodes(node) {
var next;
if (node.nodeType === 1) {
if ((node = node.firstChild)) {
do {
next = node.nextSibling;
traverseChildNodes(node);
} while((node = next));
}
} else if (node.nodeType === 3) {
if (rReps.test(node.data)) {
node.data = node.data.replace(rReps, function (match) {
return repMap[match];
});
}
}
}
}
function qS(x) {
return document.querySelector(x);
}
function unicodes(x) {
return (x.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|\n|./g) || []).map(function (c) {
return c[1] ? (c.charCodeAt(0) & 1023) * 1024 + (c.charCodeAt(1) & 1023) + 65536 : c.charCodeAt(0);
});
}
function chars(x) {
return unicodes(x).length;
}
function formatChars(x) {
var y = chars(x);
return y + ' char' + (y == 1 ? '' : 's');
}
function formatBytes(x, y) {
return x + ' ' + y + ' byte' + (x == 1 ? '' : 's');
}
function bytes(code, lang) { // Takes in a length of text and piece of header text, and returns '(# of bytes) (encoding) bytes'
var ISO_8859_1_langs = /^(Japt|TeaScript|Retina|Pyth|Reng|V)\b/i;
var ISO_8859_7_langs = /^(Jolf)\b/;
var UTF_16_langs = /^(Ziim|Funciton)\b/i;
var custom_langs = /^(GS2|Seriously|Actually|Unicorn|Jelly|M|05AB1E|2sable|(Dyalog )?APL|Charcoal|Canvas|Ohm|Brachylog|SOGL|Husk|Gaia|Neim|Stax|Pyt)\b/i;
var ISO_8859_1 = /^[\x00-\xFF]*$/;
var ISO_8859_7 = /^[\u0000-\u00A0\u2018\u2019\u00A3\u20AC\u20AF\u00A6-\u00A9\u037A\u00AB-\u00AD\u2015\u00B0-\u00B3\u0384-\u0386\u00B7\u0388-\u038A\u00BB\u038C\u00BD\u038E-\u03CE]*$/; // Taken from https://stackoverflow.com/a/34800836/4449486
lang = lang || '';
if (PARSE_HEXDUMPS && /^[[\da-f]{4,8}:? [\da-f]+ |^[\da-f]+ [\da-f\s]+$/.test(code)) {
var a = '';
code.replace(/(?:[\da-f]{2,}:|[\da-f]{6,}) ((?:[\da-f ][\da-f ] ?){10,})[^\n]*\n?/gi, function (_, z) {
a += z.replace(/\s/g, '');
});
if (a) return formatBytes(a.length / 2, 'hex');
if (/^[\da-f\s-]+$/i.test(code.replace(/\n/g, ''))) return formatBytes(code.replace(/[\s-]/g, '').length / 2, 'hex');
}
if (/whitespace/i.test(lang)) return formatBytes((code.match(/\s|\\?[snt]/gi) || []).length, 'whitespace');
if ((/iso.?8859.1/i.test(lang) || ISO_8859_1_langs.test(lang)) && ISO_8859_1.test(code)) return formatBytes(chars(code), 'ISO-8859-1');
if ((/iso.?8859.7/i.test(lang) || ISO_8859_7_langs.test(lang)) && ISO_8859_7.test(code)) return formatBytes(chars(code), 'ISO-8859-7');
if (/utf.?16/i.test(lang) || UTF_16_langs.test(lang)) return formatBytes(code.length * 2, 'UTF-16');
if (custom_langs.test(lang)) return formatBytes(chars(code), lang.match(custom_langs)[0]);
return formatBytes(unicodes(code).map(function (c) {
return c >> 16 ? 4 : c >> 11 ? 3 : c >> 7 ? 2 : 1;
}).reduce(function (a, b) {
return a + b;
}, 0), 'UTF-8');
}
function loadAnswers(onFinish) {
var answers = [],
i = 5;
function loadPage() {
$.get(
'https://api.stackexchange.com/2.2/questions/' +
String(window.location).match(/\d+/)[0] + '/answers?key=43GcpjKdprvwYoLebJVMOg((&page=' +
(page++).toString() + '&pagesize=100&order=asc&sort=creation&site=codegolf&filter=!.Fjs-H6J36vlFbqzY4mEMnTsXxwcX', readPage);
}
function readPage(data) {
if (data.hasOwnProperty('error_id'))
onFinish(data.error_id.toString());
else {
answers = answers.concat(data.items);
if (data.has_more)
loadPage();
else
onFinish(answers, console.log('answers', answers));
}
}
var page = 1;
loadPage(page, readPage);
}
////////////////////////////////////////////////////////////////////
/////////////// //////////////////
/////////////// QUESTON OF THE DAY WIDGET //////////////////
/////////////// //////////////////
////////////////////////////////////////////////////////////////////
/* Add the question of the day widget */
function addQuestionOfTheDay() {
console.log('adding question of the day');
var questionOfTheDayHtml = 'Programming Puzzles & Code Golf Challenges of the Day