-
-
Save cyrillsemenov/a21cd3073cca81b5767870add6aac1cd to your computer and use it in GitHub Desktop.
Script for "User JavaScript and CSS" Chrome extension
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
| .float#pretty-button { | |
| z-index: 2147483999; | |
| position: fixed; | |
| width: 60px; | |
| height: 60px; | |
| bottom: 30px; | |
| right: 30px; | |
| background-color: #00bcd4; | |
| color:#fff; | |
| border: none; | |
| border-radius:50px; | |
| text-align:center; | |
| } | |
| .q-highlight { | |
| background-color: yellow; | |
| } |
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
| let list = { | |
| "stackoverflow.com": _ => { | |
| console.log("This is a function for specific site"); | |
| }, | |
| "www.bbc.com": _ => { | |
| q$("nav[role=navigation], section[aria-label=Реклама]").rmAll(); | |
| q$("main[role=main]").css("width","650px"); | |
| }, | |
| "declarator.org": _ => { | |
| q$(".modal, .modal-backdrop, .main_menu, .lang_switcher, .auth, .person-new__breadcrumbs, .btn").rmAll(); | |
| window.onscroll = 0; | |
| }, | |
| "www.dw.com": _ => { | |
| q$(".adsContainer, #navMain, #navPath, #navMeta, #search, #sharing-bar, .photo_source, .profile-info>div>.row").rmAll(); | |
| q$("#navContainer").css("minHeight", "0"); | |
| }, | |
| "echo.msk.ru": _ => { | |
| q$(".bannerBlock, .secondmenu, .waves, .header_top, .title .right, .meta, #adfox_top, #mainsidebar").rmAll(); | |
| q$(".header_body .wrapper").css("display", "block"); | |
| q$(".header_body").css("minHeight", "0").css("borderBottom","0").css("height", "80px"); | |
| q$(".header").css("height", "80px"); | |
| q$(".logo > a > img").css("height", "50px").css("width", "auto"); | |
| }, | |
| "www.fontanka.ru": _ => { | |
| window.setTimeout(() => { | |
| // Надо разобраться, как сносить куски сайтов, построенных на реакте, где ублюдки не дают айди элементам, потому что такой подход не работает: | |
| // q$(".JFaed, .JFlx, .BVix, .I-l, .DBon, .DBor").rmAll(); | |
| q$("iframe, [data-google-query-id], .viqeo-flyWidget, noindex").rmAll(); | |
| q$("[href='/weather.html']").collection[0].parentElement.parentElement.parentElement.remove(); | |
| q$("button > img").collection[0].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.remove(); | |
| q$("aside").collection[0].remove(); | |
| q$("#app > div > div, footer").collection.forEach((e, i) => {if (i == 2) {return} else {e.remove()}}); | |
| app = q$("#app > div > div > div"); | |
| app.collection[1].remove(); | |
| header = app.collection[0]; | |
| header.children[1].remove(); | |
| header.children[0].remove(); | |
| article = app.collection[5].children[0].children[0].children[0].children[0].children[1].children[0].children | |
| article[0].remove(); | |
| article[0].children[1].remove(); | |
| article[0].children[0].children[1].remove(); | |
| article[0].children[0].children[1].remove() | |
| }, 2000); | |
| }, | |
| "www.vedomosti.ru": _ => { | |
| q$(".the-sidebar, .article-share, .article-tools__controls, .adfox--articles-top, .the-projects, .the-header__progress").rmAll(); | |
| q$(".the-header__toolbar").rmChildren(); | |
| q$(".the-header").css("top","0").css("position", "unset"); | |
| q$("article").css("paddingTop", "10px"); | |
| q$(".layout__container").css("paddingLeft", "0").css("maxWidth", "100%"); | |
| q$(".article__headline").css("width", "420px"); | |
| }, | |
| "www.kommersant.ru": _ => { | |
| q$("div.adv_nest, div.actual, div.doc_sharing, .vicon").rmAll(); | |
| q$("a.main_header__logo").css("position","absolute").css("left","240px").drag("x"); | |
| }, | |
| "lenta.ru": _ => { | |
| q$(".b-banner, .b-tags-list, .b-header__info, .b-topic__socials, .b-sidebar-menu, .b-topic-layout__right").rmAll(); | |
| q$("#root").css("margin-left","0"); | |
| }, | |
| "meduza.io": _ => { | |
| q$(".SaveMeduza-root, .Layout-bannerTop, .AdvPanel-root, #div-gpt-ad").rmAll(); | |
| q$(".GeneralMaterial-head").css("alignItems", "center"); | |
| q$(".Header-logo").drag("x"); | |
| }, | |
| "newtimes.ru": _ => { | |
| $(".red-menu").parent().remove(); | |
| q$(".menu-holder, .search-holder, .uptl_container-share").rmAll(); | |
| $("section > .container > div > :first-child").removeClass().addClass('col-sm-12'); | |
| }, | |
| "novayagazeta.ru": _ => { | |
| q$(".Header_linkDonate_*, .DonateLink_link_*, .SearchButton_root_*, .LoginButton_root_*, .ShopLink_rootShop_*, .Header_issueDesktop_*, div[style='position: fixed; top: 0px; left: 0px; height: 5px; width: 100%; background-color: transparent; z-index: 1298;']").rmAll(); | |
| q$("h1").css("max-width","70%").css("font-size","45px").css("line-height","45px").css("text-align","left").css("font-weight","600"); | |
| q$(".Logo_root_*, .Post_headerWrapper_*, .Header_upWrapper_*, .Content_root__*").css("paddingLeft", "60px"); | |
| }, | |
| "openmedia.io": _ => { | |
| q$(".rtb-wrapper, .header__links, .social").rmAll(); | |
| }, | |
| "ovdinfo.org": _ => { | |
| q$("#call-and-donate, #header-links, #social-column, .magiccolumns-outer .right").rmAll(); | |
| q$("header").css("height", "auto"); | |
| q$("#logo > a > img").css("width", "auto").css("height", "40px"); | |
| q$("#slogan").css("margin-top", "3px").css("line-height", "12px").css("line-height", "12px").css("font-size", "10px"); | |
| q$("#logo-and-slogan").css("height", "45px").css("padding", "7px 0 8px 45px"); | |
| }, | |
| "polit.info": _ => { | |
| q$(".header-content-block__right").rmAll(); | |
| q$(".header-content-block").css("padding","0 90px"); | |
| q$(".single__head-right").css("margin", "0"); | |
| q$(".container-flex").css("margin-top","0"); | |
| }, | |
| "www.rbc.ru": _ => { | |
| q$(".banner__filmstrip, .article__header__after, .article__header__counter-block, .article__header__share-block, .subscription-popup").rmAll(); | |
| q$(".topline__right").rmChildren(); | |
| q$(".topline__logo-block").css("marginLeft","185px"); | |
| }, | |
| "regnum.ru": _ => { | |
| q$(".article_sharing_buttons, .footer-container").rmAll(); | |
| let header = $(".article-header"); | |
| let newelem = $('<div class="article-text">'); | |
| newelem.append($(".article-info")).insertAfter(header); | |
| }, | |
| "ria.ru": _ => { | |
| q$(".article__info-statistic, .article__sharebar-line, .header__menu, .banner").rmAll(); | |
| }, | |
| "www.sports.ru": _ => { | |
| q$(".nav-line-wrapper--bottom, .nav-top-line__list-wrapper, iframe, .columns-layout__left, .branding_dfp__sitewrap, .top-ad, .social-share").rmAll(); | |
| q$("#branding-layout").css("padding-top","0"); | |
| q$(".main-nav").css("height","auto"); | |
| q$(".main-wrap").css("padding-top","40px").css("padding-left","40px"); | |
| }, | |
| "www.svoboda.org": _ => { | |
| q$("[data-trans-id=menu]").rmAll(); | |
| q$(".main-logo").drag("x"); | |
| // q$("a#main-logo-link > img.main-logo--big").css("height", "80px"); | |
| // q$(".hdr-20__side").css("height", "95px"); | |
| }, | |
| "tass.ru": _ => { | |
| q$(".banner*, .header-bar, .header-news-feed-button, .news-header__actions").rmAll(); | |
| }, | |
| "tvrain.ru": _ => { | |
| q$(".menu3__bottom, .menu3__age, .menu3__items, .menu3__bookmark,.menu3__login, .menu3__search, .document-head__f1__r, .right-col").rmAll(); | |
| // q$("amp-ad, .ampheader__button, .right-col").rmAll() | |
| q$(".wrap").css("padding-top", "0"); | |
| q$(".menu3").css("margin-bottom", "0"); | |
| q$(".menu3__logo").css("margin-left", "20px"); | |
| }, | |
| "www.znak.com": _ => { | |
| q$(".header_advert, .under, .shareBlock, [data-set-region]").rmAll(); | |
| q$(".minilogo").css("padding-left", "125px"); | |
| }, | |
| }; | |
| function common () { | |
| console.log("This is a common function"); | |
| let body = document.body | |
| let prevRng; | |
| // document.addEventListener("mouseup", checkSelection); | |
| // document.addEventListener("mousedown", checkSelection); | |
| // function checkSelection() { | |
| // var s = getSelection(), r = s.rangeCount && s.getRangeAt(0); | |
| // if (prevRng) { | |
| // if (!r || r.endContainer !== prevRng.endContainer | |
| // || r.endOffset !== prevRng.endOffset) { | |
| // // The selection has changed or been cleared | |
| // selectionClear(); | |
| // } | |
| // } | |
| // if (r) setPlaceHolder(r); | |
| // } | |
| // function setPlaceHolder(range) { | |
| // if (range.startContainer === range.endContainer | |
| // && range.startOffset === range.endOffset) { | |
| // // The selection is clear | |
| // prevRng = null; | |
| // return; | |
| // } | |
| // prevRng = range; | |
| // var endc = range.endContainer, span = document.createElement("span"), image = document.createElement("span"); | |
| // span.className = "place-holder"; | |
| // image.className = "quote-image"; | |
| // image.innerText = "H"; | |
| // span.appendChild(image); | |
| // if (endc.nodeType === Node.TEXT_NODE) { // Node.TEXT_NODE === 3 | |
| // var p1 = endc.nodeValue.substring(0, range.endOffset), | |
| // p2 = endc.nodeValue.substring(range.endOffset); | |
| // endc.nodeValue = p1; | |
| // if (p2) | |
| // endc.parentNode.insertBefore(document.createTextNode(p2), | |
| // endc.nextSibling); | |
| // } | |
| // endc.parentNode.insertBefore(image, endc.nextSibling); | |
| // } | |
| // function selectionClear() { | |
| // if (!prevRng) return; | |
| // var endc = prevRng.endContainer; | |
| // if (endc.nextSibling.className === "place-holder") { | |
| // endc.parentNode.removeChild(endc.nextSibling); | |
| // if (endc.nodeType === Node.TEXT_NODE | |
| // && endc.nextSibling.nodeType === Node.TEXT_NODE) { | |
| // // Joining previously divided text nodes | |
| // endc.nodeValue += endc.nextSibling.nodeValue; | |
| // endc.parentNode.removeChild(endc.nextSibling); | |
| // } | |
| // } | |
| // } | |
| body.addEventListener("keypress", enterKeyPressHandler, false); | |
| body.addEventListener("mouseup", selectionHandler, false); | |
| body.contentEditable = true; | |
| body.spellcheck = false; | |
| document.execCommand("defaultParagraphSeparator", false, "br"); | |
| } | |
| document.addEventListener("DOMContentLoaded", _ => { | |
| console.log("qQuery entry name:", window.location.hostname); | |
| if (Object.keys(list).includes(window.location.hostname)) { | |
| let btn = document.createElement("button"); | |
| btn.innerHTML = "Pretty"; | |
| btn.id = "pretty-button"; | |
| btn.className = "float"; | |
| console.log("Add a button"); | |
| btn.addEventListener("click", _ => { | |
| btn.remove(); | |
| common(); | |
| list[window.location.hostname](); | |
| }); | |
| document.body.appendChild(btn); | |
| console.log(btn); | |
| } | |
| }); | |
| function enterKeyPressHandler(e) { | |
| let sel, range, br, addedBr = false; | |
| evt = e || window.event; | |
| console.log(e,evt); | |
| if (e.keyCode == 13) { | |
| if (typeof window.getSelection != "undefined") { | |
| sel = window.getSelection(); | |
| if (sel.getRangeAt && sel.rangeCount) { | |
| range = sel.getRangeAt(0); | |
| range.deleteContents(); | |
| br = document.createElement("br"); | |
| range.insertNode(br); | |
| range.setEndAfter(br); | |
| range.setStartAfter(br); | |
| sel.removeAllRanges(); | |
| sel.addRange(range); | |
| e.preventDefault(); | |
| } | |
| } else if (typeof document.selection != "undefined") { | |
| sel = document.selection; | |
| if (sel.createRange) { | |
| range = sel.createRange(); | |
| range.pasteHTML("<br>"); | |
| range.select(); | |
| e.preventDefault(); | |
| } | |
| } | |
| } | |
| } | |
| function selectionHandler (e) { | |
| let span = document.createElement("span"); | |
| span.classList.add("q-highlight"); | |
| // span.style.backgroundColor = "yellow"; | |
| if (window.getSelection) { | |
| let selection = window.getSelection(); | |
| if (selection.toString() !== "") { | |
| let range = selection.getRangeAt(0).cloneRange(); | |
| let cmd = (e) => { | |
| console.log(e); | |
| if (e.keyCode == 91) { | |
| window.addEventListener("keydown", h); | |
| window.removeEventListener("keydown", cmd); | |
| } | |
| }; | |
| let h = (e) => { | |
| e.preventDefault(); | |
| window.removeEventListener("keydown", h); | |
| if (e.keyCode == 72) { | |
| range.surroundContents(span); | |
| selection.removeAllRanges(); | |
| selection.addRange(range); | |
| span.addEventListener("click", (e) => { | |
| span.replaceWith(...span.childNodes); | |
| }, { once: true }) | |
| }; | |
| }; | |
| window.addEventListener("keydown", cmd, false); | |
| } | |
| } | |
| } | |
| function Q$(selector) { | |
| selector = selector.split(", ").map((e,i,a) => { | |
| // if (e.split(".").length > 1) { | |
| // } | |
| return e.includes("*") ? `[class^=${e.substr(1,e.length-2)}]` : e | |
| }).join(","); | |
| // console.log(selector); | |
| this.collection = document.querySelectorAll(selector) || []; | |
| this.css = function(parameter, value) { | |
| this.collection.forEach(e => e.style[parameter] = value); | |
| return this | |
| }; | |
| this.rmAll = function() { | |
| this.collection.forEach(e => e.remove()); | |
| }; | |
| this.rmFirst = function() { | |
| this.collection[0].remove(); | |
| }; | |
| this.rmChildren = function() { | |
| Array.from(this.collection[0].children).forEach(e => e.remove()) | |
| }; | |
| this.drag = function (axis = false, grid = 10) { | |
| var object = this.collection[0], | |
| initX, initY, firstX, firstY; | |
| window.addEventListener("keydown", (e) => { | |
| var charCode = e.which || e.keyCode; | |
| if (charCode == 91) { | |
| setGrid(1); | |
| } | |
| }, false); | |
| window.addEventListener('keyup', (e) => { | |
| var charCode = e.which || e.keyCode; | |
| if (charCode == 91) { | |
| setGrid(10); | |
| window.removeEventListener('keydown', setGrid); | |
| } | |
| }, false); | |
| function setGrid(size) { | |
| grid = size; | |
| } | |
| object.addEventListener('mousedown', function(e) { | |
| e.preventDefault(); | |
| initX = object.offsetLeft; | |
| initY = object.offsetTop; | |
| firstX = e.pageX; | |
| firstY = e.pageY; | |
| window.addEventListener('mousemove', dragIt, false); | |
| window.addEventListener('mouseup', function() { | |
| window.removeEventListener('mousemove', dragIt, false); | |
| }, false); | |
| }, false); | |
| function dragIt(e) { | |
| function gridder (num) { | |
| return Math.round(num / grid) * grid | |
| } | |
| switch (axis.toLowerCase()) { | |
| case 'x': | |
| object.style.left = gridder(initX+e.pageX-firstX) + 'px'; | |
| break; | |
| case 'y': | |
| object.style.top = gridder(initY+e.pageY-firstY) + 'px'; | |
| break; | |
| default: | |
| object.style.left = gridder(initX+e.pageX-firstX) + 'px'; | |
| object.style.top = gridder(initY+e.pageY-firstY) + 'px'; | |
| } | |
| } | |
| } | |
| } | |
| var q$ = function(selector) { | |
| return new Q$(selector); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment