How to use screenshotSelector method in chromy

Best JavaScript code snippet using chromy

screenshot.js

Source:screenshot.js Github

copy

Full Screen

1if (!com)2 var com = {};3if (!com.VidBar)4 com.VidBar = {};56com.VidBar.ScreenshotSelector = {7 BACKGROUND_DIV : "__VidBarScreenshotBgDiv",8 GRAB_DIV : "__VidBarScreenshotDiv",9 SEL_DIV : "__VidBarScreenshotSelectDiv",1011 startSelect : function() {12 com.VidBar.__d("com.VidBar.ScreenshotSelector.startSelect");13 if (com.VidBar.ScreenshotSelector.isSelecting())14 return;1516 var win = window._content;17 var doc = win.document;1819 var body = doc.getElementsByTagName("html")[0];2021 var ScreenshotDiv = doc.createElement("div");22 ScreenshotDiv23 .setAttribute("id", com.VidBar.ScreenshotSelector.GRAB_DIV);2425 var backgroundDiv = doc.createElement("div");26 backgroundDiv.setAttribute("id",27 com.VidBar.ScreenshotSelector.BACKGROUND_DIV);28 backgroundDiv29 .setAttribute(30 "style",31 'background-color:gray;opacity:0.3;position:fixed;z-index:4721;top:0;left:0;width:100%;height:100%;');32 backgroundDiv.addEventListener("mousedown",33 com.VidBar.ScreenshotSelector.beginBoxSelect, false);3435 ScreenshotDiv.appendChild(backgroundDiv);36 body.appendChild(ScreenshotDiv);37 },38 isSelecting : function() {39 com.VidBar.__d("com.VidBar.ScreenshotSelector.isSelecting");40 var win = window._content;41 var doc = win.document;42 return doc.getElementById(com.VidBar.ScreenshotSelector.GRAB_DIV) != null;43 },44 beginBoxSelect : function(event) {45 com.VidBar.__d("com.VidBar.ScreenshotSelector.beginBoxSelect");46 var win = window._content;47 var Doc = win.document;48 var selDiv = Doc.getElementById(com.VidBar.ScreenshotSelector.SEL_DIV);49 if (selDiv == null) {50 selDiv = Doc.createElement("div");51 selDiv.setAttribute("id", com.VidBar.ScreenshotSelector.SEL_DIV);52 selDiv53 .setAttribute(54 "style",55 'z-index:4726;background-color:green;opacity:0.7;border:1px solid #000;position:absolute;');56 Doc.getElementById(com.VidBar.ScreenshotSelector.BACKGROUND_DIV)57 .appendChild(selDiv);58 }5960 selDiv.style.display = "none";61 selDiv.style.left = event.clientX + "px";62 selDiv.style.top = event.clientY + "px";63 Doc.addEventListener("mousemove",64 com.VidBar.ScreenshotSelector.doBoxSelect, true);65 Doc.addEventListener("mouseup",66 com.VidBar.ScreenshotSelector.endBoxSelect, true);67 Doc.ScreenshotSelectorData = {};68 Doc.ScreenshotSelectorData.originX = event.clientX;69 Doc.ScreenshotSelectorData.originY = event.clientY;70 },71 doBoxSelect : function(event) {72 // com.VidBar.__d("com.VidBar.ScreenshotSelector.doBoxSelect");73 var win = window._content;74 var doc = win.document;75 var selDiv = doc.getElementById(com.VidBar.ScreenshotSelector.SEL_DIV);7677 var mouseX = event.clientX;78 var mouseY = event.clientY;7980 var originX = doc.ScreenshotSelectorData.originX;81 var originY = doc.ScreenshotSelectorData.originY;82 var left = mouseX < originX ? mouseX : originX;83 var top = mouseY < originY ? mouseY : originY;8485 var width = Math.abs(mouseX - originX);86 var height = Math.abs(mouseY - originY);8788 selDiv.style.display = "none";89 selDiv.style.left = left + "px";90 selDiv.style.top = top + "px";9192 selDiv.style.width = width + "px";93 selDiv.style.height = height + "px";9495 selDiv.style.display = "inline";96 },97 endBoxSelect : function(event) {98 com.VidBar.__d("com.VidBar.ScreenshotSelector.endBoxSelect");99 var win = window._content;100 var doc = win.document;101 doc.removeEventListener("mousemove",102 com.VidBar.ScreenshotSelector.doBoxSelect, true);103 doc.removeEventListener("mouseup",104 com.VidBar.ScreenshotSelector.endBoxSelect, true);105 com.VidBar.ScreenshotSelector.finishSelect();106 },107 finishSelect : function() {108 com.VidBar.__d("com.VidBar.ScreenshotSelector.finishSelect");109 var win = window._content;110 var doc = win.document;111 var box = null;112 // create a box to hold the dimensions of the box113 var selDiv = doc.getElementById(com.VidBar.ScreenshotSelector.SEL_DIV);114 if (selDiv != null) {115 box = {116 x : selDiv.offsetLeft,117 y : selDiv.offsetTop,118 width : selDiv.clientWidth,119 height : selDiv.clientHeight120 };121 com.VidBar.__d("com.VidBar.ScreenshotSelector.box grabbed: x:"122 + box.x + " y:" + box.y + " width:" + box.width123 + " height:" + box.height);124 }125 // remove the box div126 var body = doc.getElementsByTagName("html")[0];127 var ScreenshotDiv = doc128 .getElementById(com.VidBar.ScreenshotSelector.GRAB_DIV);129 body.removeChild(ScreenshotDiv);130131 // take the shot (hopefully everything is clean now)132 if (box != null) {133 if (doc.ScreenshotOperations) {134 var data = [win, box];135 com.VidBar.Screenshot.processOperation(136 doc.ScreenshotOperations, data);137 }138 }139 }140}141142com.VidBar.Screenshot = {143 init : function(){144 com.VidBar.__d("com.VidBar.Screenshot.init");145 com.VidBar.Pref.registerObserver(146 ["save_complete_jpeg_key", "save_complete_png_key"], this);147 148 this.updateShortcutKey("vidbar_screenshot_save_complete_jpeg_key", com.VidBar.ScreenshotPref.getSaveCompleteJpegKey());149 this.updateShortcutKey("vidbar_screenshot_save_complete_png_key", com.VidBar.ScreenshotPref.getSaveCompletePngKey());150 },151 observePref : function(data) {152 if (data == "save_complete_jpeg_key")153 this.updateShortcutKey("vidbar_screenshot_save_complete_jpeg_key", com.VidBar.ScreenshotPref.getSaveCompleteJpegKey());154 else if (data == "save_complete_png_key")155 this.updateShortcutKey("vidbar_screenshot_save_complete_png_key", com.VidBar.ScreenshotPref.getSaveCompletePngKey());156 },157 updateShortcutKey : function(id, key) {158 com.VidBar.__d("com.VidBar.Screenshot.updateShortcutKey: id="+id+", key="+key);159 var key_set, key_parent;160 var key_elem = document.getElementById(id);161 162 if(key_elem){163 key_set = key_elem.parentNode;164 key_set.removeChild(key_elem);165 key_parent = key_set.parentNode;166 key_parent.removeChild(key_set);167 }168 169 key_set = document.createElement("keyset");170 171 key_elem = document.createElement("key");172 key_elem.setAttribute("id", id);173 key_elem.setAttribute("modifiers", "accel,alt");174 key_elem.setAttribute("key", key);175 if(id=="vidbar_screenshot_save_complete_jpeg_key"){176 key_elem.setAttribute("command", "vidbar_screenshot_save_complete_jpeg_cmd");177 }else if(id=="vidbar_screenshot_save_complete_png_key"){178 key_elem.setAttribute("command", "vidbar_screenshot_save_complete_png_cmd");179 }180 181 key_set.appendChild(key_elem);182 key_parent.appendChild(key_set);183 //document.getElementById(id).setAttribute("key", key);184 },185 saveComplete : function() {186 com.VidBar.__d("com.VidBar.Screenshot.saveComplete");187 com.VidBar.Screenshot.processOperation(["getComplete", "save"]);188 },189 saveVisible : function() {190 com.VidBar.__d("com.VidBar.Screenshot.saveVisible");191 com.VidBar.Screenshot.processOperation(["getVisible", "save"]);192 },193 saveSelection : function() {194 com.VidBar.__d("com.VidBar.Screenshot.saveSelection");195 com.VidBar.Screenshot.processOperation(["getSelection", "save"]);196 },197 saveAsComplete : function() {198 com.VidBar.__d("com.VidBar.Screenshot.saveAsComplete");199 com.VidBar.Screenshot.processOperation(["getComplete", "saveAs"]);200 },201 saveAsVisible : function() {202 com.VidBar.__d("com.VidBar.Screenshot.saveAsVisible");203 com.VidBar.Screenshot.processOperation(["getVisible", "saveAs"]);204 },205 saveAsSelection : function() {206 com.VidBar.__d("com.VidBar.Screenshot.saveAsSelection");207 com.VidBar.Screenshot.processOperation(["getSelection", "saveAs"]);208 },209 copyComplete : function() {210 com.VidBar.__d("com.VidBar.Screenshot.copyComplete");211 com.VidBar.Screenshot.processOperation(["getComplete", "copy"]);212 },213 copyVisible : function() {214 com.VidBar.__d("com.VidBar.Screenshot.copyVisible");215 com.VidBar.Screenshot.processOperation(["getVisible", "copy"]);216 },217 copySelection : function() {218 com.VidBar.__d("com.VidBar.Screenshot.copySelection");219 com.VidBar.Screenshot.processOperation(["getSelection", "copy"]);220 },221 saveCompleteJpeg : function() {222 com.VidBar.__d("com.VidBar.Screenshot.saveCompleteJpeg");223 com.VidBar.Screenshot.processOperation(["getComplete", "saveJpeg"]);224 },225 saveCompletePng : function() {226 com.VidBar.__d("com.VidBar.Screenshot.saveCompletePng");227 com.VidBar.Screenshot.processOperation(["getComplete", "savePng"]);228 },229 processOperation : function(operations, data, delay) {230 if (operations.length == 0)231 return;232 if (!delay)233 delay = 0;234 var op = operations.shift();235 var t = setTimeout( function(){236 clearTimeout(t);237 com.VidBar.Screenshot.doOperation( op, operations, data );238 }, delay);239 },240 doOperation : function(op, operations, data) {241 try {242 com.VidBar.__d("com.VidBar.Screenshot.doOperation - " + op);243 com.VidBar.Screenshot[op](operations, data);244 } catch (e) {245 com.VidBar.__e(e);246 }247 },248 getComplete : function(operations, data) {249 com.VidBar.__d("com.VidBar.Screenshot.getComplete");250 operations = ["getContentFrame", "getCompletePage"].concat(operations);251 com.VidBar.Screenshot.processOperation(operations, data);252 },253 getVisible : function(operations, data) {254 com.VidBar.__d("com.VidBar.Screenshot.getVisible");255 operations = ["getContentWindow", "getVisiblePortion"]256 .concat(operations);257 com.VidBar.Screenshot.processOperation(operations, data);258 },259 getSelection : function(operations, data) {260 com.VidBar.__d("com.VidBar.Screenshot.getSelection");261 var selectOperations;262 selectOperations = ["startSelection"];263 operations = selectOperations.concat(operations);264 com.VidBar.Screenshot.processOperation(operations, data);265 },266 getContentFrame : function(operations, data) {267 com.VidBar.__d("com.VidBar.Screenshot.getContentFrame");268 var win = document.commandDispatcher.focusedWindow;269 if (!win || !(win.document instanceof HTMLDocument)) {270 com.VidBar.__d("com.VidBar.Screenshot.no focused win");271 win = window.top.getBrowser().selectedBrowser.contentWindow;272 }273 com.VidBar.Screenshot.processOperation(operations, win);274 },275 getContentWindow : function(operations, data) {276 com.VidBar.__d("com.VidBar.Screenshot.getContentWindow");277 var win = window.top.getBrowser().selectedBrowser.contentWindow;278 com.VidBar.Screenshot.processOperation(operations, win);279 },280 getCompletePage : function(operations, data) {281 com.VidBar.__d("com.VidBar.Screenshot.getCompletePage");282 var win = data;283 var htmlDoc = win.document;284 var htmlWin = win; // .content.window;285 var width = com.VidBar.Screenshot.getDocWidth(htmlDoc);286 var height = com.VidBar.Screenshot.getDocHeight(htmlDoc);287 var vWidth = com.VidBar.Screenshot.getViewportWidth(htmlDoc);288 if (vWidth > width)289 width = vWidth;290 var vHeight = com.VidBar.Screenshot.getViewportHeight(htmlDoc);291 if (vHeight > height)292 height = vHeight;293 var box = {294 x : 0,295 y : 0,296 "width" : width,297 "height" : height298 };299 var canvas = com.VidBar.Screenshot.drawToCanvas(htmlWin, box);300 com.VidBar.Screenshot.processOperation(operations, canvas);301 },302 getVisiblePortion : function(operations, data) {303 com.VidBar.__d("com.VidBar.Screenshot.getVisiblePortion");304 var win = data;305 var htmlDoc = win.document;306 var htmlWin = win.content.window;307 var box = {308 x : htmlWin.scrollX,309 y : htmlWin.scrollY,310 width : com.VidBar.Screenshot.getViewportWidth(htmlDoc),311 height : com.VidBar.Screenshot.getViewportHeight(htmlDoc)312 };313 var canvas = com.VidBar.Screenshot.drawToCanvas(htmlWin, box);314 com.VidBar.Screenshot.processOperation(operations, canvas);315 },316 startSelection : function(operations, data) {317 com.VidBar.__d("com.VidBar.Screenshot.startSelection");318 var win = window._content;319 var Doc = win.document;320 operations.unshift("finishSelection");321 Doc.ScreenshotOperations = operations;322 Doc.ScreenshotData = data;323 com.VidBar.ScreenshotSelector.startSelect();324 },325 finishSelection : function(operations, data) {326 com.VidBar.__d("com.VidBar.Screenshot.finishSelection");327 var win = data[0]328 var box = data[1];329 var htmlDoc = win.document;330 var htmlWin = win; // .content.window;331332 // adjust coordination while the doc is scrolled333 box.x += com.VidBar.Screenshot.getDocLeft(htmlDoc);334 box.y += com.VidBar.Screenshot.getDocTop(htmlDoc);335336 var canvas = com.VidBar.Screenshot.drawToCanvas(htmlWin, box);337 com.VidBar.Screenshot.processOperation(operations, canvas);338 },339 save : function(operations, data) {340 com.VidBar.__d("com.VidBar.Screenshot.save");341 var canvas = data;342 var file = com.VidBar.Screenshot.getNewFile();343344 com.VidBar.Screenshot.saveCanvas(canvas, file,345 com.VidBar.ScreenshotPref.getDefaultMimeType());346 com.VidBar.Screenshot.processOperation(operations, file);347 },348 saveTemp : function(operations, data) {349 com.VidBar.__d("com.VidBar.Screenshot.saveTemp");350 var canvas = data;351 var file = com.VidBar.Screenshot.getTempFile();352353 com.VidBar.Screenshot.saveCanvas(canvas, file,354 com.VidBar.ScreenshotPref.getDefaultMimeType());355 com.VidBar.Screenshot.processOperation(operations, file);356 },357 saveAs : function(operations, data) {358 com.VidBar.__d("com.VidBar.Screenshot.saveAs");359 var canvas = data;360361 var fp = Components.classes["@mozilla.org/filepicker;1"]362 .createInstance(Components.interfaces.nsIFilePicker);363364 fp365 .init(window, "Save As",366 Components.interfaces.nsIFilePicker.modeSave);367 fp.defaultString = com.VidBar.Screenshot.getNewFileName();368 fp.appendFilter("PNG", "*.png");369 fp.appendFilter("JPG", "*.jpg");370 if (com.VidBar.ScreenshotPref.getDefaultMimeType() == "image/png") {371 fp.filterIndex = 0;372 } else {373 fp.filterIndex = 1;374 }375376 var result = fp.show();377 if (result == fp.returnOK || result == fp.returnReplace) {378 var file = fp.file;379 var type = "image/png";380 var path = file.path;381 if (fp.filterIndex == 1) {382 type = "image/jpeg";383 if (path.substr(path.lastIndexOf(".")).toLowerCase() != ".jpg") {384 path += ".jpg";385 }386 } else {387 type = "image/png";388 if (path.substr(path.lastIndexOf(".")).toLowerCase() != ".png") {389 path += ".png";390 }391 }392 com.VidBar.__d("com.VidBar.Screenshot.save as " + path);393 file = Components.classes["@mozilla.org/file/local;1"]394 .createInstance(Components.interfaces.nsILocalFile);395 file.initWithPath(path);396 com.VidBar.Screenshot.saveCanvas(canvas, file, type);397 com.VidBar.Screenshot.processOperation(operations, file);398 }399 },400 savePng : function(operations, data) {401 com.VidBar.__d("com.VidBar.Screenshot.savePng");402 var canvas = data;403 var type = "image/png";404 var file = com.VidBar.Screenshot.getNewFile(type);405406 com.VidBar.Screenshot.saveCanvas(canvas, file, type);407 com.VidBar.Screenshot.processOperation(operations, file);408 },409 saveJpeg : function(operations, data) {410 com.VidBar.__d("com.VidBar.Screenshot.saveJpeg");411 var canvas = data;412 var type = "image/jpeg";413 var file = com.VidBar.Screenshot.getNewFile(type);414415 com.VidBar.Screenshot.saveCanvas(canvas, file, type);416 com.VidBar.Screenshot.processOperation(operations, file);417 },418 copy : function(operations, data) {419 com.VidBar.__d("com.VidBar.Screenshot.copy");420 var canvas = data;421422 var dataUrl = canvas.toDataURL("image/png", "");423 var image = window.content.document.createElement("img");424 image.setAttribute("style", "display: none");425 image.setAttribute("id", "screengrab_buffer");426 image.setAttribute("src", dataUrl);427 var body = window.content.document.getElementsByTagName("html")[0];428 body.appendChild(image);429430 operations.unshift("finishCopy");431 com.VidBar.Screenshot.processOperation(operations, image, 1000);432 },433 finishCopy : function(operations, data) {434 com.VidBar.__d("com.VidBar.Screenshot.finishCopy");435 var image = data;436437 document.popupNode = image;438 try {439 goDoCommand('cmd_copyImageContents');440 } catch (ex) {441 com.VidBar.__e(ex);442 } 443 var parent = image.parentNode;444 parent.removeChild(image);445 com.VidBar.Screenshot.processOperation(operations, image, 200);446 // play sound447 com.VidBar.SoundPool.instance.play("sound");448 },449 getDocTop : function(doc) {450 return (doc.compatMode == "CSS1Compat")451 ? doc.documentElement.scrollTop452 : doc.body.scrollTop;453 },454 getDocLeft : function(doc) {455 return (doc.compatMode == "CSS1Compat")456 ? doc.documentElement.scrollLeft457 : doc.body.scrollLeft;458 },459 getDocWidth : function(doc) {460 return (doc.compatMode == "CSS1Compat")461 ? doc.documentElement.scrollWidth462 : doc.body.scrollWidth;463 },464 getDocHeight : function(doc) {465 return (doc.compatMode == "CSS1Compat")466 ? doc.documentElement.scrollHeight467 : doc.body.scrollHeight;468 },469 getViewportHeight : function(doc) {470 return (doc.compatMode == "CSS1Compat")471 ? doc.documentElement.clientHeight472 : doc.body.clientHeight;473 },474 getViewportWidth : function(doc) {475 return (doc.compatMode == "CSS1Compat")476 ? doc.documentElement.clientWidth477 : doc.body.clientWidth;478 },479 drawToCanvas : function(win, box) {480 com.VidBar.__d("com.VidBar.Screenshot.drawToCanvas: x:" + box.x + " y:"481 + box.y + " width:" + box.width + " height:" + box.height);482 var canvas = document.createElementNS("http://www.w3.org/1999/xhtml",483 "html:canvas");484 canvas.style.width = box.width + "px";485 canvas.style.height = box.height + "px";486 canvas.width = box.width;487 canvas.height = box.height;488 var ctx = canvas.getContext("2d");489 ctx.clearRect(0, 0, box.width, box.height);490 ctx.save();491 ctx.drawWindow(win, box.x, box.y, box.width, box.height,492 "rgba(0,0,0,0)");493 ctx.restore();494 return canvas;495 },496 getNewFileName : function(type) {497 var win = window._content;498 var doc = win.document;499 var domain = doc.domain;500 var d = new Date();501 var timeString = [d.getFullYear(), d.getMonth() + 1, d.getDate(),502 d.getHours(), d.getMinutes(), d.getSeconds()].join("-");503 var name;504 name = "com.VidBar.Screenshot";505 name = domain + " screen capture " + timeString;506 if (!type || (type != "image/png" && type != "image/jpeg"))507 type = com.VidBar.ScreenshotPref.getDefaultMimeType();508 if (type == "image/png") {509 name += ".png";510 } else {511 name += ".jpg";512 }513 return name;514 },515 getNewFile : function(type) {516 var file = com.VidBar.ScreenshotPref.getSaveFolder();517 file.append(com.VidBar.Screenshot.getNewFileName(type));518 return file;519 },520 getTempFile : function() {521 var file = Components.classes["@mozilla.org/file/directory_service;1"]522 .getService(Components.interfaces.nsIProperties).get("TmpD",523 Components.interfaces.nsIFile);524 file.append(com.VidBar.Screenshot.getNewFileName());525 file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);526 return file;527 },528 saveCanvas : function(canvas, file, mimeType) {529 com.VidBar.__d("com.VidBar.Screenshot.saveCanvas");530 // create a data url from the canvas and then create URIs of the source531 // and targets532 var io = Components.classes["@mozilla.org/network/io-service;1"]533 .getService(Components.interfaces.nsIIOService);534 var source = io.newURI(canvas.toDataURL(mimeType, ""), "UTF8", null);535 var target = io.newFileURI(file)536537 // prepare to save the canvas data538 var persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]539 .createInstance(Components.interfaces.nsIWebBrowserPersist);540541 persist.persistFlags = Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_REPLACE_EXISTING_FILES;542 persist.persistFlags |= Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;543544 // displays a download dialog (remove these 3 lines for silent download)545 var xfer = Components.classes["@mozilla.org/transfer;1"]546 .createInstance(Components.interfaces.nsITransfer);547 xfer.init(source, target, "", null, null, null, persist);548 persist.progressListener = xfer;549550 // save the canvas data to the file551 persist.saveURI(source, null, null, null, null, file);552 // play sound553 com.VidBar.SoundPool.instance.play("sound");554 },555 onButtonClick : function(event) {556 com.VidBar.__d("com.VidBar.Screenshot.onButtonClick");557 var operations = [com.VidBar.ScreenshotPref.getDefaultTarget(),558 com.VidBar.ScreenshotPref.getDefaultAction()];559 com.VidBar.Screenshot.processOperation(operations);560 }561};562563com.VidBar.ScreenshotPref = {564 getDefaultMimeType : function() {565 var type = com.VidBar.Pref.getCharPref("default_type", "image/png");566 if (type != "image/png" && type != "image/jpeg")567 type = "image/png";568 return type;569 },570 setDefaultMimeType : function(type) {571 if (type != "image/png" && type != "image/jpeg")572 type = "image/png";573 com.VidBar.Pref.setCharPref("default_type", type);574 },575 getDefaultTarget : function() {576 var target = com.VidBar.Pref.getCharPref("default_target",577 "getComplete");578 if (!target)579 target = "getComplete";580 return target;581 },582 setDefaultTarget : function(target) {583 if (target != "getComplete" && target != "getVisible"584 && target != "getSelection")585 target = "getComplete";586 com.VidBar.Pref.setCharPref("default_target", target);587 },588 getDefaultAction : function() {589 var action = com.VidBar.Pref.getCharPref("default_action", "save");590 if (!action)591 action = "save";592 return action;593 },594 setDefaultAction : function(action) {595 if (action != "save" && action != "saveAs" && action != "copy")596 action = "save";597 com.VidBar.Pref.setCharPref("default_action", action);598 },599 getDefaultFolder : function() {600 com.VidBar.__d("com.VidBar.ScreenshotPref.getDefaultFolder");601 var file = null;602 try {603 file = Components.classes["@mozilla.org/file/directory_service;1"]604 .getService(Components.interfaces.nsIProperties).get(605 "Desk", Components.interfaces.nsIFile);606 } catch (e) {607 try {608 file = Components.classes["@mozilla.org/file/directory_service;1"]609 .getService(Components.interfaces.nsIProperties).get(610 "TmpD", Components.interfaces.nsIFile);611 } catch (e) {612 }613 }614 return file;615 },616 getSaveFolder : function() {617 com.VidBar.__d("com.VidBar.ScreenshotPref.getSaveFolder");618 var fileName = com.VidBar.Pref.getUnicharPref("default_folder", null);619620 var file;621 if (fileName == null || fileName.length == 0) {622 file = this.getDefaultFolder();623 } else {624 file = Components.classes["@mozilla.org/file/local;1"]625 .createInstance(Components.interfaces.nsILocalFile);626 file.initWithPath(fileName);627 if (file.exists()) {628 if (!file.isWritable() || !file.isDirectory())629 file = this.getDefaultDir();630 } else {631 try {632 file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE,633 0775);634 } catch (e) {635 file = this.getDefaultDir();636 }637 }638 }639 if (!file.exists()) {640 file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775);641 }642 com.VidBar.Pref.setUnicharPref("default_folder", file.path);643 return file;644 },645 setSaveFolder: function(dir) {646 com.VidBar.__d("com.VidBar.ScreenshotPref.setSaveFolder");647 com.VidBar.Pref.setUnicharPref("default_folder", dir);648 },649 getSaveCompleteJpegKey: function(){650 com.VidBar.__d("com.VidBar.ScreenshotPref.getSaveCompleteJpegKey");651 var key = com.VidBar.Pref.getCharPref("save_complete_jpeg_key", "J");652 if(!key || key==""){653 key = "J";654 }655 return key;656 },657 setSaveCompleteJpegKey: function(key){658 com.VidBar.__d("com.VidBar.ScreenshotPref.setSaveCompleteJpegKey");659 com.VidBar.Pref.setCharPref("save_complete_jpeg_key", key)660 },661 getSaveCompletePngKey: function(){662 com.VidBar.__d("com.VidBar.ScreenshotPref.getSaveCompletePngKey");663 var key = com.VidBar.Pref.getCharPref("save_complete_png_key", "P");664 if(!key || key==""){665 key = "P";666 }667 return key;668 },669 setSaveCompletePngKey: function(key){670 com.VidBar.__d("com.VidBar.ScreenshotPref.setSaveCompletePngKey");671 com.VidBar.Pref.setCharPref("save_complete_png_key", key);672 } ...

Full Screen

Full Screen

FavoriteScreenshots.js

Source:FavoriteScreenshots.js Github

copy

Full Screen

1import React from "react";2import imageOne from "../images/Splinter-Cell-1.webp"3import ImageTwo from "../images/MK11.webp"4import ImageThree from "../images/Metro.webp"5import ImageFour from "../images/PsychoNauts.webp"6import ImageFive from "../images/TR.webp"7import { Link } from "react-router-dom"89let screenshotSelector;1011export default function FavoriteScreenshots(){1213 function revealHiddenOne(){14 screenshotSelector=1;15 };16 function revealHiddenTwo(){17 screenshotSelector=2;18 };19 function revealHiddenThree(){20 screenshotSelector=3;21 };22 function revealHiddenFour(){23 screenshotSelector=4;24 };25 function revealHiddenFive() {26 screenshotSelector=5;27 };2829 return(30 <div id="favorite-screenshots-container" className="favorite-screenshots-container">31 <div className="favorite-screenshots-header">32 <h2>Favorite Screenshots</h2>33 </div>34 <div className="favorite-screenshots">35 <button onClick={revealHiddenOne}><Link to="/favoritescreenshots"><img src={imageOne}></img></Link></button>36 <button onClick={revealHiddenTwo}><Link to="/favoriteScreenshots"><img src={ImageTwo}></img></Link></button>37 <button onClick={revealHiddenThree}><Link to="/favoriteScreenshots"><img src={ImageThree}></img></Link></button>38 <button onClick={revealHiddenFour}><Link to="/favoriteScreenshots"><img src={ImageFour}></img></Link></button>39 <button onClick={revealHiddenFive}><Link to="/favoriteScreenshots"><img src={ImageFive}></img></Link></button>40 </div>41 </div>42 )43}44 ...

Full Screen

Full Screen

screenshots.js

Source:screenshots.js Github

copy

Full Screen

1describe("smart alec screenshots", () => {2 beforeEach(() => {3 cy.log("visiting site and waiting for animations");4 cy.visit("/").wait(2000); // Wait for initial profile animation to finish.5 cy.log("scrolling to smart alec section");6 // TODO: Simplify selector.7 cy.get(".experience.experience--smart-alec").scrollIntoView({8 eaasing: "linear",9 duration: 200010 });11 });12 it("should display a different screenshot in browser svg when a project feature is clicked", () => {13 // TODO: Simplify selector.14 const screenshotSelector =15 ".experience.experience--smart-alec .browser svg #Browser #Screenshot";16 cy.get(screenshotSelector)17 .invoke("attr", "href")18 .then(prevSrc => {19 cy.findByText(/^multiple\stime\szones\ssupport$/i).click();20 cy.get(screenshotSelector)21 .invoke("attr", "href")22 .then(nextSrc => {23 expect(nextSrc).to.not.equal(prevSrc);24 });25 });26 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var Chromy = require('chromy');2var chromy = new Chromy();3chromy.chain()4 .screenshotSelector('body', 'body.png')5 .end()6 .then(function() {7 console.log('done');8 })9 .catch(function(err) {10 console.log(err);11 });12### .goto(url, [options])13- `options` - (optional) An object with the following properties:14 - `waitUntil` - (optional) When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:15### .evaluate(fn, [arg1], [arg2], [...])16### .evaluateAsync(fn, [arg1], [arg2], [...])

Full Screen

Using AI Code Generation

copy

Full Screen

1var chromy = new Chromy({visible: true});2chromy.chain()3 .screenshotSelector('body', 'body.png')4 .end()5 .then(function() {6 console.log('done');7 });8### Chromy(options)

Full Screen

Using AI Code Generation

copy

Full Screen

1const chromy = new Chromy({ port: 9222 });2chromy.chain()3 .screenshotSelector('h1', 'h1.png')4 .end()5 .then(() => console.log('Done'))6 .catch((e) => console.log(e))7 .then(() => chromy.close());8![h1](

Full Screen

Using AI Code Generation

copy

Full Screen

1var chromy = require('chromy')2chromy.chain()3 .screenshotSelector('body', 'google.png')4 .end()5 .then(function () {6 console.log('done')7 })8 .catch(function (err) {9 console.log(err)10 })11#### `new Chromy([options])`12* `options` (Object) - [Puppeteer's launch options](

Full Screen

Using AI Code Generation

copy

Full Screen

1const Chromy = require('chromy');2const chromy = new Chromy({visible: true, waitTimeout: 20000});3(async () => {4 await chromy.type('input[name="q"]', 'Hello World');5 await chromy.tap('input[name="btnK"]');6 await chromy.wait('h3');7 await chromy.screenshotSelector('h3', 'h3.png');8 await chromy.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const chromy = new Chromy();2await chromy.screenshotSelector('body', 'body.png');3await chromy.close();4const chromy = new Chromy();5await chromy.screenshot('body.png');6await chromy.close();7const chromy = new Chromy();8await chromy.screenshot('body.png', {9 clip: {10 }11});12await chromy.close();13const chromy = new Chromy();14await chromy.screenshotSelector('body', 'body.png', {15 clip: {16 }17});18await chromy.close();19const chromy = new Chromy();20await chromy.screenshot('body.png', {21});22await chromy.close();23const chromy = new Chromy();24await chromy.screenshotSelector('body', 'body.png', {25});26await chromy.close();27const chromy = new Chromy();28await chromy.screenshot('body.png', {29});30await chromy.close();31const chromy = new Chromy();32await chromy.screenshotSelector('body', 'body.png', {33});34await chromy.close();

Full Screen

Using AI Code Generation

copy

Full Screen

1const chromy = new Chromy();2chromy.screenshotSelector('body', 'body.png')3.then(() => {4 chromy.close();5});6const chromy = new Chromy();7chromy.screenshot('body.png')8.then(() => {9 chromy.close();10});111. [Basic example](

Full Screen

Using AI Code Generation

copy

Full Screen

1const chromy = new Chromy({visible: true, waitTimeout: 5000, port:9222, host:'localhost'})2chromy.chain()3 .screenshotSelector('body', 'test.png')4 .end()5 .then(() => {6 console.log('Screenshot taken')7 })8 .catch(e => {9 console.log('Error:', e)10 })11const chromy = new Chromy({visible: true, waitTimeout: 5000, port:9222, host:'localhost'})12chromy.chain()13 .screenshot('test.png')14 .end()15 .then(() => {16 console.log('Screenshot taken')17 })18 .catch(e => {19 console.log('Error:', e)20 })21const chromy = new Chromy({visible: true, waitTimeout: 5000, port:9222, host:'localhost'})22chromy.chain()23 .screenshot('test.png')24 .end()25 .then(() => {26 console.log('Screenshot taken')27 })28 .catch(e => {29 console.log('Error:', e)30 })31const chromy = new Chromy({visible: true, waitTimeout: 5000, port:9222, host:'localhost'})32chromy.chain()33 .screenshot('test.png')34 .end()35 .then(() => {36 console.log('Screenshot taken')37 })38 .catch(e => {39 console.log('Error:', e)40 })41const chromy = new Chromy({visible: true, waitTimeout: 5000, port:9222, host:'localhost'})42chromy.chain()43 .screenshot('test.png')44 .end()45 .then(() => {46 console.log('Screenshot taken')47 })48 .catch(e => {49 console.log('Error:', e)50 })

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run chromy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful