├── Pipfile ├── README.md ├── background.js ├── code.png ├── code128.png ├── code256.png ├── code512.png ├── manifest.json ├── scnShot.html ├── script.js └── style.css /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | name = "pypi" 3 | url = "https://pypi.org/simple" 4 | verify_ssl = true 5 | 6 | [dev-packages] 7 | 8 | [packages] 9 | 10 | [requires] 11 | python_version = "3.8" 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # c-code 2 | copy code from Youtube videos ! 3 | 4 | # Installation on Google chrome 5 | 6 | 1 - Download the code. 7 | 2 - Open the Extension Management page by navigating to chrome://extensions. 8 | 3 - Enable Developer Mode by clicking the toggle switch next to Developer mode. 9 | 4 - Click the LOAD UNPACKED button and select the extension directory. 10 | -------------------------------------------------------------------------------- /background.js: -------------------------------------------------------------------------------- 1 | var id = 100; 2 | 3 | chrome.browserAction.onClicked.addListener(function() { 4 | 5 | 6 | chrome.tabs.captureVisibleTab(null, { format : "png"}, function(screenshotUrl) { 7 | 8 | var viewTabUrl = chrome.extension.getURL('scnShot.html?' + screenshotUrl) 9 | var tagetID = null; 10 | chrome.tabs.create({ url: viewTabUrl},); 11 | 12 | console.log(viewTabUrl) 13 | }); 14 | }); -------------------------------------------------------------------------------- /code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ghiles1010/c-code/680cac37d20e412f6f2e8811dea2ed0e225f0d6e/code.png -------------------------------------------------------------------------------- /code128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ghiles1010/c-code/680cac37d20e412f6f2e8811dea2ed0e225f0d6e/code128.png -------------------------------------------------------------------------------- /code256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ghiles1010/c-code/680cac37d20e412f6f2e8811dea2ed0e225f0d6e/code256.png -------------------------------------------------------------------------------- /code512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ghiles1010/c-code/680cac37d20e412f6f2e8811dea2ed0e225f0d6e/code512.png -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "name": "CCode", 4 | "version": "1.1", 5 | "manifest_version": 2, 6 | 7 | "permissions": [ 8 | "activeTab", 9 | "downloads", 10 | "notifications", 11 | "" 12 | ], 13 | 14 | "icons": { 15 | 16 | "64": "code.png", 17 | "128": "code128.png", 18 | "256": "code256.png", 19 | "512": "code512.png" 20 | 21 | }, 22 | 23 | "browser_action":{ 24 | 25 | "default_title": "Take a screen shot of your code!" 26 | }, 27 | 28 | "background": { 29 | "scripts": ["background.js"] 30 | }, 31 | 32 | "content_security_policy": "script-src 'self' 'unsafe-eval' https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.5.7/cropper.js https://code.jquery.com/jquery-3.5.1.min.js ; object-src 'self'" 33 | 34 | 35 | } -------------------------------------------------------------------------------- /scnShot.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 |

Crop the image to select your code

8 | 9 |
10 |
11 | 12 | 13 |
14 | hi 15 | 16 | ho 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /script.js: -------------------------------------------------------------------------------- 1 | 2 | var done = document.getElementById("done"); 3 | var img = document.getElementById("screenShot"); 4 | var test = document.getElementById("test"); 5 | var form = document.getElementById("form"); 6 | var res = ""; 7 | var URL = "https://c-code.herokuapp.com/"; 8 | 9 | var scr_url = window.location.search.substr(1); 10 | img.setAttribute("src", scr_url) 11 | 12 | 13 | cropper = new Cropper(img, { 14 | crop(event){ 15 | 16 | const imgURL = this.cropper.getCroppedCanvas().toDataURL(); 17 | test.src = imgURL; 18 | 19 | } 20 | }); 21 | 22 | 23 | 24 | 25 | 26 | done.addEventListener("click", () =>{ 27 | 28 | 29 | var ImageURL = test.src 30 | var block = ImageURL.split(";"); 31 | // Get the content type of the image 32 | var contentType = block[0].split(":")[1];// In this case "image/gif" 33 | // get the real base64 content of the file 34 | var realData = block[1].split(",")[1];// In this case "R0lGODlhPQBEAPeoAJosM...." 35 | 36 | // Convert it to a blob to upload 37 | var blob = b64toBlob(realData, contentType); 38 | 39 | var formDataToUpload = new FormData(form); 40 | formDataToUpload.append("image", blob); 41 | 42 | $(document.body).css({'cursor' : 'wait'}); 43 | 44 | $.ajax({ 45 | url:URL, 46 | data: formDataToUpload, 47 | type:"POST", 48 | contentType:false, 49 | processData:false, 50 | cache:false, 51 | error:function(err){ 52 | console.error(err); 53 | }, 54 | success:function(data){ 55 | console.log(data); 56 | copyStringToClipboard(data); 57 | alert("Success: text has been copied to clipboard !"); 58 | }, 59 | complete:function(){ 60 | $(document.body).css({'cursor' : 'default'}); 61 | console.log("Request finished."); 62 | } 63 | }); 64 | 65 | 66 | }) 67 | 68 | 69 | 70 | function copyStringToClipboard (str) { 71 | // Create new element 72 | var el = document.createElement('textarea'); 73 | // Set value (string to be copied) 74 | el.value = str; 75 | // Set non-editable to avoid focus and move outside of view 76 | el.setAttribute('readonly', ''); 77 | el.style = {position: 'absolute', left: '-9999px'}; 78 | document.body.appendChild(el); 79 | // Select text inside element 80 | el.select(); 81 | // Copy text to clipboard 82 | document.execCommand("copy") 83 | // Remove temporary element 84 | document.body.removeChild(el); 85 | } 86 | 87 | function b64toBlob(b64Data, contentType, sliceSize) { 88 | contentType = contentType || ''; 89 | sliceSize = sliceSize || 512; 90 | 91 | var byteCharacters = atob(b64Data); 92 | var byteArrays = []; 93 | 94 | for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) { 95 | var slice = byteCharacters.slice(offset, offset + sliceSize); 96 | 97 | var byteNumbers = new Array(slice.length); 98 | for (var i = 0; i < slice.length; i++) { 99 | byteNumbers[i] = slice.charCodeAt(i); 100 | } 101 | 102 | var byteArray = new Uint8Array(byteNumbers); 103 | 104 | byteArrays.push(byteArray); 105 | } 106 | 107 | var blob = new Blob(byteArrays, {type: contentType}); 108 | return blob; 109 | } 110 | 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | h1 2 | { 3 | 4 | color: blueviolet; 5 | } 6 | 7 | 8 | --------------------------------------------------------------------------------