From 5b294855ae5a8df1e3219133eee4ed67b852beee Mon Sep 17 00:00:00 2001 From: Mauro Date: Fri, 10 Oct 2014 21:08:05 +0200 Subject: [PATCH 01/15] Added whitelisting instructions. The extension isn't disabled on startup. --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index bbeb4d1..0ea00fa 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,13 @@ This is a Chrome extension which modifies pages on [cplusplus.com](http://www.cp ## Rationale Why are these features not part of the site already? The site owner is very busy and does not have time to add these features for us. These features don't require any server-side work so we can implement them ourselves. Plus, it effectively means the community can make the site look and act as they wish. + +## Installation +By default, Chrome now disables non-store extensions, such as this extension. To enable them, you have to whitelist the extensions. To enable whitelisting, we need to copy two files. You can download a zip [here](https://dl.dropboxusercontent.com/u/83943521/publicaccess/Files/admx.zip). +* Go to %windir%/policydefinitions and copy the chrome.admx file. Find your language in the zip, and copy the inner chrome.adml to %windir%/policydefinitions/yourlanguage . +* Find the Extension ID. Go to chrome://extensions and enable Developer Mode. Note down the Extension ID for the extension you want to whitelist. +* Run gpedit.msc (Win+R) and browse to: User Configuration/Administrative Templates/Google/Google Chrome/Extensions +* Double click "Configure extension installation whitelist" (this is usually localized to your own language), choose Enable and click on Show. +* In the list, paste the Extension IDs to whitelist. On my system, this extension has the ID gcgeapgjphgeiaibnolfidoilmnjcjeb . I have no idea if it changes from system to system. Make sure to check in your Extensions page. +* Click OK and Restart Chrome. In the extensions page, it will take some seconds before the Enable checkbox is ungreyed. +* To further whitelist more extensions, restart from point 2. From a68c0d04abb5abee8808c595ac8ec2a387babefb Mon Sep 17 00:00:00 2001 From: Mauro Date: Fri, 10 Oct 2014 21:18:37 +0200 Subject: [PATCH 02/15] Tiny changes --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0ea00fa..5baaee6 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,10 @@ Why are these features not part of the site already? The site owner is very busy ## Installation By default, Chrome now disables non-store extensions, such as this extension. To enable them, you have to whitelist the extensions. To enable whitelisting, we need to copy two files. You can download a zip [here](https://dl.dropboxusercontent.com/u/83943521/publicaccess/Files/admx.zip). -* Go to %windir%/policydefinitions and copy the chrome.admx file. Find your language in the zip, and copy the inner chrome.adml to %windir%/policydefinitions/yourlanguage . +* Go to `%windir%/policydefinitions` and copy the `chrome.admx` file. Find your language in the zip, and copy the inner `chrome.adml` to `%windir%/policydefinitions/yourlanguage` . * Find the Extension ID. Go to chrome://extensions and enable Developer Mode. Note down the Extension ID for the extension you want to whitelist. -* Run gpedit.msc (Win+R) and browse to: User Configuration/Administrative Templates/Google/Google Chrome/Extensions -* Double click "Configure extension installation whitelist" (this is usually localized to your own language), choose Enable and click on Show. -* In the list, paste the Extension IDs to whitelist. On my system, this extension has the ID gcgeapgjphgeiaibnolfidoilmnjcjeb . I have no idea if it changes from system to system. Make sure to check in your Extensions page. +* Run `gpedit.msc` (Win+R) and browse to: `User Configuration/Administrative Templates/Google/Google Chrome/Extensions` +* Double click `Configure extension installation whitelist` (this is usually localized to your own language), choose `Enable` and click on `Show`. +* In the list, paste the Extension IDs to whitelist. On my system, this extension has the ID `gcgeapgjphgeiaibnolfidoilmnjcjeb` . I have no idea if it changes from system to system. Make sure to check in your Extensions page. * Click OK and Restart Chrome. In the extensions page, it will take some seconds before the Enable checkbox is ungreyed. -* To further whitelist more extensions, restart from point 2. +To further whitelist more extensions, restart from point 2. From 6b63a53c0a815f34fbc80694c3b4c5a20218ef2d Mon Sep 17 00:00:00 2001 From: Mauro Date: Fri, 10 Oct 2014 21:20:52 +0200 Subject: [PATCH 03/15] Installation section completeness I make way too many commits for this kind of stuff. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5baaee6..cc5e606 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,10 @@ This is a Chrome extension which modifies pages on [cplusplus.com](http://www.cp Why are these features not part of the site already? The site owner is very busy and does not have time to add these features for us. These features don't require any server-side work so we can implement them ourselves. Plus, it effectively means the community can make the site look and act as they wish. ## Installation +Download the [latest release](https://github.com/cpluspluscom/EnhancedCpp.com/releases), open `chrome://extensions` and drag-and-drop the .crx file in that page. By default, Chrome now disables non-store extensions, such as this extension. To enable them, you have to whitelist the extensions. To enable whitelisting, we need to copy two files. You can download a zip [here](https://dl.dropboxusercontent.com/u/83943521/publicaccess/Files/admx.zip). * Go to `%windir%/policydefinitions` and copy the `chrome.admx` file. Find your language in the zip, and copy the inner `chrome.adml` to `%windir%/policydefinitions/yourlanguage` . -* Find the Extension ID. Go to chrome://extensions and enable Developer Mode. Note down the Extension ID for the extension you want to whitelist. +* Find the Extension ID. Go to `chrome://extensions` and enable Developer Mode. Note down the Extension ID for the extension you want to whitelist. * Run `gpedit.msc` (Win+R) and browse to: `User Configuration/Administrative Templates/Google/Google Chrome/Extensions` * Double click `Configure extension installation whitelist` (this is usually localized to your own language), choose `Enable` and click on `Show`. * In the list, paste the Extension IDs to whitelist. On my system, this extension has the ID `gcgeapgjphgeiaibnolfidoilmnjcjeb` . I have no idea if it changes from system to system. Make sure to check in your Extensions page. From 01ed7c9cc08a626aaa7e96eb3d4d2521d944630d Mon Sep 17 00:00:00 2001 From: Mauro Date: Tue, 21 Oct 2014 01:23:56 +0200 Subject: [PATCH 04/15] Added Coliru as an optional compilation target. Reworked options page. --- js/base.js | 8 ++++ js/coliru_run.js | 3 ++ js/enumerate.js | 8 ++++ js/main.js | 16 -------- js/options.js | 1 + js/transform.js | 61 +++++++++++++++++++++++++++++++ manifest.json | 7 +++- options/css/custom.css | 4 ++ options/css/res/bg.png | Bin 0 -> 100229 bytes options/css/res/bgh.png | Bin 0 -> 118 bytes options/css/res/bgv.png | Bin 0 -> 1055 bytes options/css/res/link.png | Bin 0 -> 416 bytes options/css/style.css | 1 + options/js/defaults.js | 16 ++++++++ options/js/optpage.js | 40 ++++++++++---------- options/options.html | 77 ++++++++++++++++++++++++++++++++++----- 16 files changed, 197 insertions(+), 45 deletions(-) create mode 100644 js/coliru_run.js create mode 100644 options/css/custom.css create mode 100644 options/css/res/bg.png create mode 100644 options/css/res/bgh.png create mode 100644 options/css/res/bgv.png create mode 100644 options/css/res/link.png create mode 100644 options/css/style.css create mode 100644 options/js/defaults.js diff --git a/js/base.js b/js/base.js index 08a6e85..5d85ee1 100644 --- a/js/base.js +++ b/js/base.js @@ -1,4 +1,12 @@ // dev'ed by SGH. Ideas by LB. Uploading fee provided by BHXSpecter. +function FindParent(item,matchfunc) +{ + do { + if(matchfunc(item)) + return item; + } while(item = item.parentNode); +} +function GetText(b,c){if(typeof c==="undefined"){return b.textContent||b.innerText}else{if(b.textContent){b.textContent=c}else{b.innerText=c}}} function CloneItem(item) // Clone and item and its childs' callbacks. { // Used by Code spoilers. var cloned = item.cloneNode(false); // We clone the first node. diff --git a/js/coliru_run.js b/js/coliru_run.js new file mode 100644 index 0000000..bd27b86 --- /dev/null +++ b/js/coliru_run.js @@ -0,0 +1,3 @@ +var data=function(){var query_string={};var query=window.location.search.substring(1);var vars=query.split("&");for(var i=0;i 0, output -> 3 } + var AllCodeBlocks = document.getElementsByClassName('btn trans_half'); + for(var i = 0; i != AllCodeBlocks.length; ++i) + { + IsEditablePage = 1; + + forEachItem(AllCodeBlocks[i],4,CanReply); // [compile with] box -> 4 + } + } while(0); // The reason behind the do/while(0) is so I can break out of this if the page is not a topic's page. // This allows me to not having to add multiple nested ifs. diff --git a/js/main.js b/js/main.js index 9a3abf8..7c6b144 100644 --- a/js/main.js +++ b/js/main.js @@ -1,19 +1,3 @@ -var defaultOptions = -{ - allow_quote:'1', - allow_code:'0', - splow_quote:'1', - splow_code:'0', - splow_outp:'1', - spl_qopen:'0', - spl_qsz:'20', - spl_qxsz:'35', - spl_copen:'1', - spl_csz:'20', - spl_popen:'0', - spl_psz:'20' -}; - chrome.storage.sync.get(defaultOptions, function(items) { for(var k in items) diff --git a/js/options.js b/js/options.js index 01a4f69..b89d4b3 100644 --- a/js/options.js +++ b/js/options.js @@ -20,6 +20,7 @@ function CodeButtonAllowed(){return currentOptions['allow_code'];} function QuoteSpoilerAllowed(){return currentOptions['splow_quote'];} function CodeSpoilerAllowed(){return currentOptions['splow_code'];} function OutputSpoilerAllowed(){return currentOptions['splow_outp'];} +function CompileAllowed(){return currentOptions['allow_cbox'];} function IsQuoteOpenDefault(){return currentOptions['spl_qopen'];} function IsCodeOpenDefault(){return currentOptions['spl_copen'];} diff --git a/js/transform.js b/js/transform.js index 1727a92..cd6c9f1 100644 --- a/js/transform.js +++ b/js/transform.js @@ -85,6 +85,67 @@ function forEachItem(Item, Type, IsReplyable) newdiv.appendChild(CloneItem(Item)); Item.parentNode.replaceChild(newdiv,Item); } + if(Type==4 && CompileAllowed()) + { + Item.style.height = "32px"; + Item.style.whiteSpace = "nowrap"; + Item.onmouseout = function(){ + Item.style.width = "16px"; + Item.style.backgroundColor = "#FFF"; + } + Item.onmouseover = function(){ + Item.style.width = "100px"; + Item.style.backgroundColor = "#FFD"; + } + + Item.firstChild.firstChild.style.backgroundImage = "url('http://cpp.sh/favicon.ico')"; + Item.firstChild.firstChild.style.backgroundSize = "16px"; + Item.firstChild.firstChild.className = "C_ico"; + + var newa = document.createElement('a'); + newa.href = '#'; // set onclick + newa.onclick = function() + { + var snippetElem = FindParent(newa,function(elem){ + return elem.className == "snippet"; + }); + if(snippetElem) + { + var srcElem = snippetElem.getElementsByClassName('source'); + if(srcElem.length) + { + var code = GetText(srcElem[0]); + window.open('http://coliru.stacked-crooked.com/?src='+escape(code),'_blank'); + } + } + // Go upwards from Item, finding the "snippet" classnamed table. + // From the "snippet" classnamed table, find a "source" classnamed table. + // Run dom.text(mysourceclassnamedelement) + // Store it. It's the code we want to compile. + + // Open a coliru page as follows: + // window.open('http://coliru.stacked-crooked.com','_blank'); + // Execute: + // app.defaultCmd = "ourcode"; + // app.resetCommand(); + // on it after the page has loaded. + // NOTE: DO NOT USE document.onload ! COLIRU ALREADY USES IT! + // We probably should use + // window.open().document.addEventListener('load',function(){...}); + // Inject the code via - \ No newline at end of file + + From ed3e1cd6f31f5918e49a00f58bdf71a2844aefee Mon Sep 17 00:00:00 2001 From: Mauro Date: Tue, 21 Oct 2014 01:30:16 +0200 Subject: [PATCH 05/15] Updated Version Info --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 52a848a..6d0cd65 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version" : 2, "name" : "Enhanced Cpp.com", "description" : "Author: SGH", - "version" : "1.6", + "version" : "1.7", "homepage_url" : "https://github.com/cpluspluscom/EnhancedCpp.com", "options_page" : "options/options.html", From a65cd9e1e04fab8a95c2163ea7c506cb31373e3e Mon Sep 17 00:00:00 2001 From: Ronak Gajrawala Date: Sat, 7 Feb 2015 18:36:07 -0800 Subject: [PATCH 06/15] Prettify everything --- css/style.css | 56 +- js/base.js | 94 +- js/coliru_run.js | 27 +- js/enumerate.js | 211 +++-- js/main.js | 36 +- js/options.js | 143 ++- js/transform.js | 190 ++-- manifest.json | 39 +- options/css/custom.css | 21 +- options/css/style.css | 1933 +++++++++++++++++++++++++++++++++++++++- options/js/defaults.js | 31 +- options/js/optpage.js | 94 +- options/options.html | 192 ++-- 13 files changed, 2628 insertions(+), 439 deletions(-) diff --git a/css/style.css b/css/style.css index d3a9444..c81edde 100644 --- a/css/style.css +++ b/css/style.css @@ -1,10 +1,46 @@ -.noselect {-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;} -.C_ico.ascode {background-image:url(http://www.cplusplus.com/ico/text_code.png);} -.snippet{tab-size:4;} -.quote{display:block;height:auto;} -.hiddenicon{background-position: -80px -96px;} -.shownicon{background-position: -64px -96px;} -.ofhide{overflow:hidden;} -.ofshow{overflow:visible;} -.codeSpan{vertical-align:top;font-size:8px;} -.codeButton{padding-left:12px;} \ No newline at end of file +.noselect { + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.C_ico.ascode { + background-image: url(http://www.cplusplus.com/ico/text_code.png); +} + +.snippet { + tab-size: 4; +} + +.quote { + display: block; + height: auto; +} + +.hiddenicon { + background-position: -80px -96px; +} + +.shownicon { + background-position: -64px -96px; +} + +.ofhide { + overflow: hidden; +} + +.ofshow { + overflow: visible; +} + +.codeSpan { + vertical-align: top; + font-size: 8px; +} + +.codeButton { + padding-left: 12px; +} diff --git a/js/base.js b/js/base.js index 5d85ee1..766347c 100644 --- a/js/base.js +++ b/js/base.js @@ -1,46 +1,60 @@ // dev'ed by SGH. Ideas by LB. Uploading fee provided by BHXSpecter. -function FindParent(item,matchfunc) -{ + +function FindParent(item, matchFunc) { do { - if(matchfunc(item)) + if (matchFunc(item)) { return item; - } while(item = item.parentNode); + } + } while (item = item.parentNode); } -function GetText(b,c){if(typeof c==="undefined"){return b.textContent||b.innerText}else{if(b.textContent){b.textContent=c}else{b.innerText=c}}} -function CloneItem(item) // Clone and item and its childs' callbacks. -{ // Used by Code spoilers. - var cloned = item.cloneNode(false); // We clone the first node. + +function GetText(b, c) { + if (c === undefined) { + return b.textContent || b.innerText; + } else if (b.textContent) { + b.textContent = c; + } else { + b.innerText = c; + } +} + +// Clone and item and its childs' callbacks. +// Used by Code spoilers. +function CloneItem(item) { + // We clone the first node. + var cloned = item.cloneNode(false); + // We lose the first node's callbacks. No way to save them reliably, but we don't need them. // The childs are shared to preserve callbacks. - for(var i = 0; i < item.childNodes.length; ++i) - { + for (var i = 0; i < item.childNodes.length; i++) { cloned.appendChild(item.childNodes[i]); } + return cloned; } -function ToggleDisplay( TargetDiv, DisplayIcon, ShortSize ) // Called by spoiler's 's onclick handler -{ - if(TargetDiv.style.height == "auto") // Already expanded? - { + +function ToggleDisplay(targetDiv, displayIcon, shortSize) { // Called by spoiler's 's onclick handler + if (targetDiv.style.height == "auto") { // Already expanded? // Close - TargetDiv.className = "ofhide"; //overflow:hidden - TargetDiv.style.height = ShortSize; - DisplayIcon.className = "C_ico hiddenicon"; - } - else - { + targetDiv.className = "ofhide"; // overflow: hidden + targetDiv.style.height = shortSize; + displayIcon.className = "C_ico hiddenicon"; + } else { // Open - TargetDiv.className = "ofshow"; //overflow:display (required for cpp.sh icon) - TargetDiv.style.height = "auto"; - DisplayIcon.className = "C_ico shownicon"; + targetDiv.className = "ofshow"; // overflow: display (required for cpp.sh icon) + targetDiv.style.height = "auto"; + displayIcon.className = "C_ico shownicon"; } } -function RunJavascriptCode(Script) // Add a - - - + + + + + Options - C++ Forum + + + + +
+
+ + +
+ +
+
+
+
+
+
+
+
+

Options

+
+
+ + + + + + + + + + + + + +
+
by SGH
+ Change your options here! +
Welcome to the Options page! You are now free to change this extension's behaviour!
Oct 21, 2014 at 00:24am
+  [73 replies] Last: oh god i am so lazy (by Twicker) +
+
+
+
+
+
+ +
+
+
Oct 21, 2014 at 00:24am
+ +
+
+
+ +
+
+
+ +
+
+
+
+ +
+
+
+ +
+

+
+
+
+
+ Report +
+
+
+
+
+ +
+
+
+
+ +
+ + + + From a5201ce16d0b67113ab2ca34fe04105f18380dd9 Mon Sep 17 00:00:00 2001 From: Ronak Gajrawala Date: Sun, 8 Feb 2015 12:32:03 -0800 Subject: [PATCH 07/15] 2015, added quote on all pages --- LICENSE.md | 2 +- js/enumerate.js | 25 +++++++++++++++++-------- js/quote.js | 10 ++++++++++ manifest.json | 4 ++-- options/options.html | 2 +- 5 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 js/quote.js diff --git a/LICENSE.md b/LICENSE.md index 6f240eb..346235f 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2014 - Mauro Grassia +Copyright (c) 2014-2015 - Mauro Grassia Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by diff --git a/js/enumerate.js b/js/enumerate.js index 5fe58b6..4122bb1 100644 --- a/js/enumerate.js +++ b/js/enumerate.js @@ -2,7 +2,7 @@ function RunPageEdit() { var isEditablePage = 0; do { // Can I reply? (aka Can I quote a post?) - var canReply = +(document.getElementsByClassName('postreply').length !== 0); + var canReply = +(document.querySelector('#CH_subscription > form > select').children.length > 2); var currentTopic = document.location.pathname; // Parse Topic ID @@ -103,18 +103,27 @@ function RunPageEdit() { var js_quote_code = 'for_Post.prototype.quote = ' + (function() { var result = getpostinternal(this.postid); if (result !== 'error') { - var reply = document.getElementById('CH_reply').getElementsByTagName('a'); - if (reply[0].href.indexOf('javascript:thread') === 0) { - eval(reply[0].href.substr(11) + ';'); - } - reply = document.getElementById('CH_reply').getElementsByTagName('textarea'); + var pages = document.querySelector('.C_pages'); + var on_last_page = pages ? !!pages.lastChild.title : true; var replier = this.el.innerHTML; var begin = replier.indexOf(''); var end = replier.indexOf(''); - replier = (begin > 0 && end > 0) ? ('=' + replier.substring(begin + 3, end)) : ''; - reply[0].value ='[quote' + replier + ']' + result + '[/quote]'; + + if (on_last_page) { + var reply = document.getElementById('CH_reply').getElementsByTagName('a'); + if (reply[0].href.indexOf('javascript:thread') === 0) { + eval(reply[0].href.substr(11) + ';'); + } + reply = document.getElementById('CH_reply').getElementsByTagName('textarea'); + + reply[0].value = '[quote' + replier + ']' + result + '[/quote]'; + } else { + localStorage.setItem('q_body', '[quote' + replier + ']' + result + '[/quote]'); + localStorage.setItem('q_tid', window.location.pathname.split('/').slice(3,4)[0]); + window.location.href = pages.lastChild.href; + } } }).toString() + ';'; diff --git a/js/quote.js b/js/quote.js new file mode 100644 index 0000000..54d1ae8 --- /dev/null +++ b/js/quote.js @@ -0,0 +1,10 @@ +var q_body = localStorage.getItem('q_body'); +var q_tid = localStorage.getItem('q_tid'); +if (q_body && q_tid && window.location.pathname.indexOf(q_tid) !== -1 && document.getElementById('CH_reply')) { + var reply = document.getElementById('CH_reply').getElementsByTagName('a')[0].click(); + reply = document.getElementById('CH_reply').getElementsByTagName('textarea'); + + reply[0].value = q_body; +} +localStorage.removeItem('q_body'); +localStorage.removeItem('q_tid'); diff --git a/manifest.json b/manifest.json index 88a3e58..3059693 100644 --- a/manifest.json +++ b/manifest.json @@ -21,8 +21,8 @@ "content_scripts" : [ { "matches" : ["http://www.cplusplus.com/*"], - "run_at" : "document_end", - "js" : ["options/js/defaults.js", "js/options.js", "js/base.js", "js/transform.js", "js/enumerate.js", "js/main.js"], + "run_at" : "document_idle", + "js" : ["options/js/defaults.js", "js/options.js", "js/base.js", "js/transform.js", "js/enumerate.js", "js/main.js", "js/quote.js"], "css" : ["css/style.css"] }, { diff --git a/options/options.html b/options/options.html index 84a41a5..195a59a 100644 --- a/options/options.html +++ b/options/options.html @@ -107,7 +107,7 @@

Forum