User:Recludam/common.js

$(document).ready(function {    /* Customized Special:Upload form */    if (mw.config.get('wgCanonicalSpecialPageName') === 'Upload') {        var setupCustomUploadForm = function  {            /* Hide existing Summary box */            $('tr.mw-htmlform-field-HTMLTextAreaField').hide;            /* Bind submit button to checkUpload function */            $('#mw-upload-form').submit(checkUpload);            /* Disable submit button until a license is selected */            checkLicense;            /* Remove license preview */            $('#mw-license-preview').remove;            /* Minor licensing label tweak (+semicolon for label consistency) */            $('.mw-htmlform-field-Licenses label').text('Licensing:');            /* Declare custom table row entries */            var trFileOwner = ' Creator/Owner:  KJPSIE    '; var trFileSrc = ' Source:  Death Stranding  <input id="cufFileSrcInputField" size="30" disabled>  '; var trFileTypes = ' <td class="mw-label"><label for="cufFileTypes">File type(s): <td class="mw-input"><form id="cufFileTypes"><input type="radio" name="cufFileTypes" value="artwork"> Artwork <input type="radio" name="cufFileTypes" value="logo"> Logo <input type="radio" name="cufFileTypes" value="merchandise"> Merchandise <input type="radio" name="cufFileTypes" value="photo"> Photo <input type="radio" name="cufFileTypes" value="true"> Render <input type="radio" name="cufFileTypes" value="screenshot"> Screenshot <input type="radio" name="cufFileTypes" value="symbol"> Symbol <input type="radio" name="cufFileTypes" value="wiki"> Wiki '; var trFileSubjs = ' <td class="mw-label"><label for="cufFileSubjs">Subjects featured: <td class="mw-input"><input id="cufFileSubjs" size="60" placeholder="Characters, places, concepts, objects, etc., featured in file"> '; /* Add new required table rows */ var cufNewTrs = trFileOwner + trFileSrc + trFileTypes + trFileSubjs; if (window.location.search.indexOf('wpForReUpload=1') === -1) { //$($.parseHTML(cufNewTrs)).insertAfter('.mw-htmlform-field-Licenses'); } else { var trFileLicense = ''; }           var $tbody = $('#mw-htmlform-description').children('tbody').eq(0); $tbody.append(trFileOwner); $tbody.append(trFileSrc); $tbody.append(trFileTypes); $tbody.append(trFileSubjs); $('.mw-label').css({'width': '150px'}); $('#wpLicense').css({'width': '394px'}); $('input[name="cufFileOwner"], input[name="cufFileSrc"]').click(function {                var $this = $(this);                var $pairedInput = $this.next;                var $currEnabled = $this.siblings(':enabled:not([type=radio])');                $pairedInput.prop('disabled', false);                $currEnabled.prop('disabled', true);            }); };       var checkUpload = function  { // If filename is found to be funky, prevent upload if (!checkFilename) return false; var $wpLicense = $('#wpLicense'); var fileLicense = $('#wpLicense').val; var fileOwner = $('#cufFileOwnerInputField').is(':checked') ? $('#cufFileOwnerInputField').val : $('#cufFileOwnerRadioKjpsie').val; var fileSrc = $('#cufFileSrcInputField').is(':checked') ? $('#cufFileSrcInputField').val : $('#cufFileSrcSelect').children('option:selected').val; var $fileTypesInput = $('input[name=cufFileTypes]:checked'); var fileTypes = $fileTypesInput.length === 0 ? '' : $fileTypesInput .map(function {                    return $(this).val;                }) .get .join(', '); var fileSubjs = $('#cufFileSubjs').val; var fileDetails = getFileDetails; var tmplFileInfo = '';           $('#wpUploadDescription').val(tmplFileInfo); $wpLicense.prop('selectedIndex', 0); return true; };       var checkReupload = function  { // If filename is found to be funky, prevent upload if (!checkFilename) return false; var $wpLicense = $('#wpLicense'); /* Check if license has been changed */ if ($wpLicense.val !== '') { $('#wpUploadDescription').val(                   $('#wpUploadDescription').val.replace('| license    = ', '| license    = ' + $wpLicense.val)                ); $wpLicense.prop('selectedIndex', 0); }           return true; };       var checkFilename = function  { var filename = $('#wpDestFile').val; /* Check for duplicated or capitalized file extensions */ if (filename.match(/(JPG|JPEG|PNG|GIF|SVG|jpg.jpg|jpeg.jpeg|png.png|gif.gif|svg.svg)$/)) { alert('Please do not use capitalized or duplicated file extensions in the filename.'); return false; }           /* Check for annoying characters */ if (filename.match(/(\(|\)|!|\?|,|\+|\*)/)) { alert('Please do not use parentheses, slashes, punctuation marks, or other non-alphanumeric characters in your filename.'); return false; }           return true; };       var checkLicense = function  { var $license = $('#wpLicense'); var $btnSubmit = $('input.mw-htmlform-submit'); $license.change(function {                if ($(this).val) {                    $btnSubmit.prop('disabled', false);                } else {                    $btnSubmit.prop('disabled', true);                }            }); if (!$license.val) { $btnSubmit.prop('disabled', true); }           return true; };       var getFileDetails = function  { var fileThumbInfo = $('#mw-upload-thumbnail .fileinfo').text.split(/\s×\s|\s|,\s/); var fileIsBig = fileThumbInfo[3] === 'MB' ? 'yes' : 'no'; var fileDetails = { resWidth: fileThumbInfo[0], resHeight: fileThumbInfo[1], isBig: fileIsBig };           return fileDetails; };       setupCustomUploadForm; }

/* r/DeathStranding JSON data fetching, for main page news updates */ if (mw.config.get('wgIsMainPage')) { $.getJSON(           'https://www.reddit.com/r/DeathStranding.json?jsonp=?',            function foo(data) {                $.each( data.data.children.slice(0, 30), function (i, post) { if ($('.ri-linklisting tr').length === 10) { return; } else if (post.data.stickied) { if (post.data.thumbnail === 'self') { $('.ri-linklisting-stickied').append(' <a href="' + post.data.url + '" class="self"/> <a href="' + post.data.url + '"> ' + post.data.title + ' </a>  ');

} else { $('.ri-linklisting-stickied').append(' <a href="' + post.data.url + '">' + '<img src="' + post.data.thumbnail + '"></a> <a href="' + post.data.url + '"> ' + post.data.title + ' </a>  '); }                       } else if (post.data.thumbnail !== 'self' && !post.data.spoiler && post.data.ups > 20) { $('.ri-linklisting').append(' <a href="' + post.data.url + '">' + '<img src="' + post.data.thumbnail + '"></a> <a href="' + post.data.url + '"> ' + post.data.title + ' </a>  ' + post.data.ups + ' upvotes  · <a href="https://www.reddit.com' + post.data.permalink + '">' + post.data.num_comments + ' comments</a>    '); }                   }                );            }        );    } });