Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
rojer committed Feb 19, 2018
2 parents 00d1774 + 074c0cc commit 13d9939
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 33 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ It has now been removed from the webstore, reportedly for user privacy violation

If you are familiar with the original Awesome Screenshot, you'll feel right at home.

Here are the things I added, in addition to removing all the crap:
Here are the things I added, in addition to removing all the junk:

++ Desktop capture - used to be a "premium feature", i re-implemented it myself.
++ Desktop capture - used to be a "premium feature", I re-implemented it myself.
++ GDrive URL shortening - short "goo.gl/foo" urls for screenshots uploaded to GDrive.
++ (coming soon) Touch screen support.

Expand Down
65 changes: 44 additions & 21 deletions javascripts/content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ function initEntireCapture(){
vLast = hLast = false;
getDocumentNode();
html = doc.documentElement;
initScrollTop = document.body.scrollTop;
initScrollLeft = document.body.scrollLeft;
initScrollTop = html.scrollTop;
initScrollLeft = html.scrollLeft;
clientH = getClientH();
clientW = html.clientWidth;
document.body.scrollTop = 0;
document.body.scrollLeft = 0;
html.scrollTop = 0;
html.scrollLeft = 0;
var scrollBar = getScrollBar();
if (scrollBar.x || scrollBar.y) {
setTimeout(sendRequest,150,{action:"scroll_next_done"});
Expand All @@ -33,10 +33,16 @@ function initEntireCapture(){
}
}

/*
* Determines if there's a horiztonal or vertical scrollbar.
* @return An object o where:
* o['x'] === true if there's a horizontal scrollbar
* o['y'] === true if there's a vertical scrollbar
*/
function getScrollBar() {
return {
x: (window.innerHeight > getClientH()),
y: (document.body.scrollHeight > window.innerHeight)
y: (document.documentElement.scrollHeight > getClientH())
};
}

Expand Down Expand Up @@ -296,9 +302,15 @@ function getStyle(a,b){
return parseInt(a.style.getPropertyValue(b));
}

/*
* The general algorithm is to work in columns: start at column 0, take screenshots all
* the way down, then scroll over to column 1 and repeat until the whole doc is covered.
*/
function scrollNext() {
var scrollTop = document.body.scrollTop;
var scrollLeft = document.body.scrollLeft;

// All references to `html` are to `document.documentElement`
var scrollTop = html.scrollTop;
var scrollLeft = html.scrollLeft;
console.log('scrollNext', scrollLeft, scrollTop);
enableFixedPosition(false);
var scrollBar = getScrollBar();
Expand Down Expand Up @@ -370,36 +382,47 @@ function scrollNext() {
}
}
} else {
document.body.scrollTop = scrollTop + clientH;
if (document.body.scrollTop == scrollTop || vLast) {
var scrollLeft = document.body.scrollLeft;
document.body.scrollLeft = scrollLeft + clientW;
if (!scrollBar.x || document.body.scrollLeft == scrollLeft || hLast) {

// Scroll down by 1 clientH
html.scrollTop = scrollTop + clientH;

// Can't scroll vertically any further.
if (!scrollBar.y || html.scrollTop == scrollTop) {

// Scroll right by 1 clientW
var scrollLeft = html.scrollLeft;
html.scrollLeft = scrollLeft + clientW;

// Can't scroll horizontally any further
if (!scrollBar.x || html.scrollLeft == scrollLeft) {
var remainderRatio = {
y: (scrollTop % clientH / clientH),
x: (scrollLeft % clientW / clientW)
};
document.body.scrollTop = initScrollTop;
document.body.scrollLeft = initScrollLeft;

// Reset the scroll bars back to their positions at time of capture
html.scrollTop = initScrollTop;
html.scrollLeft = initScrollLeft;

enableFixedPosition(true);

// No more columns to make, so capture is done.
sendRequest({
action: "entire_capture_done",
numColumns: numColumns,
remainderRatio: remainderRatio,
scrollBar: scrollBar
});
return;
} else {
hLast = (document.body.scrollLeft - scrollLeft < clientW);
}
}

// Starting next column
numColumns++;
document.body.scrollTop = 0;
html.scrollTop = 0;
vLast = false;
fixAndCapture();
return;
} else {
vLast = (document.body.scrollTop - scrollTop) < clientH;
}
}
}
fixAndCapture();
}
Expand Down
13 changes: 8 additions & 5 deletions javascripts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ function getDevicePixelRatio() {
return window.devicePixelRatio || 1;
}
function prepareEditArea(req) {

/* https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage */
function addTileY(imgSrc, sx, sy, sw, sh, dx, dy, dw, dh){
dy = counterY * (imageHeight / getDevicePixelRatio());
dx = counterX * (imageWidth / getDevicePixelRatio());
if (counterY == numTilesY - 1) {
sy = imageHeight - lastH;
dh = (lastH / getDevicePixelRatio());
Expand All @@ -21,7 +24,7 @@ function prepareEditArea(req) {
});
}
function addTileX(imgSrc, sx, sy, sw, sh, dx, dy, dw, dh){
dx = counterX * imageWidth;
dx = counterX * (imageWidth / getDevicePixelRatio());
if (counterX == numTilesX - 1) {
sx = imageWidth - lastW;
sw = dw = lastW;
Expand All @@ -40,11 +43,11 @@ function prepareEditArea(req) {
var columnOffsetX, columnWidth;
if (counterX == numTilesX - 1) {
centerOffX = imageWidth - lastW;
columnWidth = editW - counterX * imageWidth;
columnWidth = (editW - counterX * imageWidth) / getDevicePixelRatio();
columnOffsetX = counterX * imageWidth;
} else {
centerOffX = 0;
columnWidth = imageWidth;
columnWidth = imageWidth / getDevicePixelRatio();
columnOffsetX = counterX * imageWidth;
}
centerOffY = 0;
Expand Down Expand Up @@ -136,7 +139,7 @@ function prepareEditArea(req) {
addMargin();
getEditOffset();
var sourceWidth = imageWidth * getDevicePixelRatio();
var sourceHeight = imageHeight * getDevicePixelRatio();
var sourceHeight = imageHeight * getDevicePixelRatio();
addTileY(images[0], centerOffX, centerOffY, sourceWidth, sourceHeight, 0, 0, imageWidth, imageHeight);
} else if (scrollBar.x && !scrollBar.y) {
imageHeight -= scrollbarWidth;
Expand All @@ -146,7 +149,7 @@ function prepareEditArea(req) {
if (scrollBar.realY) imageWidth -= scrollbarWidth;
editH = req.centerH * getDevicePixelRatio();
} else {
editH = imageHeight;
editH = imageHeight / getDevicePixelRatio();
}
editW = lastW ? imageWidth * (numTilesX - 1) + lastW : imageWidth * numTilesX;
updateEditArea();
Expand Down
2 changes: 1 addition & 1 deletion javascripts/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $(document).ready(function(){
var tabURL = a.url;
// Can't inject scripts into chrome extension gallery or non-html pages.
if (tabURL.match(/https:\/\/chrome.google.com\/webstore\/category\/extensions/) ||
!tabURL.match(/https?:\/\/*\/*/gi)) {
!tabURL.match(/(https?|file):\/\/*\/*/gi)) {
canInject = false;
$("#entire, #selected, #delayed")
.attr({title:chrome.i18n.getMessage("disableEntireTitle")})
Expand Down
8 changes: 4 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
"browser_action": {
"default_icon": "images/icon19.png",
"default_popup": "popup.html",
"default_title": "Awesome Screenshot Minus"
"default_title": "Awesome Screenshot Minus (Beta)"
},
"content_scripts": [ {
"js": [ "javascripts/shortcuts.js" ],
"matches": [ "http://*/*", "https://*/*" ],
"run_at": "document_end"
} ],
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiT0O9fnWAlXj2J4LWtNrV/l3pR3F8v34NZe5J3WkViRqbeYT48VWvC9/w0l5ORd5XgmV1vtVmT8JviyrN+5LBSvEePj86lwe7KJVI++09NgVCHZBOE50BA+M3WFl2VJ5OTYX8cLGsc9Q0Xwz0SAIdR0B4LN4PymXNJTQU/ljf0q5sVj7bD4yoYTyF+AA4nWOaypmXVrWZfsDqjgaw73wG2ZArzshiDL5nEoVeTPln7KYBhR+BMcrmeQazBu81ohEqOvXFYaaspMhiWqnMVn0DRCkeLmtlW8M9Sh6jQWfvhr5wmw+J+390NDWtI+S+EUdG+J+CrK+OlTYeKDy8qXuzwIDAQAB",
"default_locale": "en",
"description": "Awesome Screenshot Minus all the junk",
"icons": {
Expand All @@ -21,9 +20,10 @@
"32": "images/icon32.png",
"48": "images/icon48.png"
},
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjEWSb8wg8/Vnb0izCNjarloprZTfDiIEX8hSFV3nwg/e/Or8gGn/YIBJWVXZ5OWurCsb4eSDPdvi2XoH93ChMBfx8s19Euw7ZQgcI5olhZIgxqK+/s8sZ7v9ukI10DqDJlX7BzUA2bCo40Jjq1eNh7/DCf20u4Ovh5eutsXObZKYGqqZEg1ChDzmNLJcqpfjZcVtYGySdsvTOsj2Z9xNkAAehsm72EzdEfJ5IJmlHVlRYItKcS0TlHxf25qnQEUzBBVqKlKhxNxMn9w6jZP+9xSlp+2LUUYwJ7sNhR0649VSjtlVZ+wRPPlTX5KmhYeT/q+CNMnfOZ0kFah+FsM1KwIDAQAB",
"manifest_version": 2,
"minimum_chrome_version": "37.0",
"name": "Awesome Screenshot Minus",
"name": "Awesome Screenshot Minus (Beta)",
"options_page": "options.html",
"permissions": [
"<all_urls>",
Expand All @@ -39,7 +39,7 @@
"version": "4.0.1.0",
"web_accessible_resources": [ "images/success.gif", "images/clear.png", "images/icon19.png", "chrome-extension://bnophbnknjcjnbadhhkciahanapffepm/#" ],
"oauth2": {
"client_id": "681609840281-r5gak4k2lbk69pcvgf59v0btkp1kp476.apps.googleusercontent.com",
"client_id": "681609840281-98ot9gn10qpakv9m2p3b02envjru1qpb.apps.googleusercontent.com",
"scopes": []
}
}

0 comments on commit 13d9939

Please sign in to comment.