Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

v5.0 Context Menu

  • Loading branch information...
commit 04b0e0ab5d99aa50c9fdf99e4010e9eaca7c0704 1 parent 43bb4c8
@codysherman authored
View
21 background.html
@@ -1,6 +1,6 @@
<script>
-// Creates options defaults in case user hasn't set them yet.
+// Creates options defaults in case user hasn't set them yet
if (!localStorage["scroll_speed"]) {
localStorage["scroll_speed"] = 1000;
}
@@ -16,9 +16,6 @@
if (!localStorage["arrow"]) {
localStorage["arrow"] = "arrow_blue";
}
- /*if (!localStorage["scroll"]) {
- localStorage["scroll"] = "jswing";
- }*/
if (!localStorage["location"]) {
localStorage["location"] = "TR";
}
@@ -28,6 +25,9 @@
if (!localStorage["transparency"]) {
localStorage["transparency"] = "0.5";
}
+ if (!localStorage["contextmenu"]) {
+ localStorage["contextmenu"] = "on";
+ }
if (!localStorage["loadcount"]) {
localStorage["loadcount"] = "0";
}
@@ -37,6 +37,13 @@
localStorage["bothered"]="1";
}
}
+ if ((localStorage["loadcount"]>=3) && (localStorage["bothered2"]!="1")) {
+ chrome.tabs.create({url:'http://scrolltotopbutton.tumblr.com/STTBdonate',selected:false});
+ localStorage["bothered2"]="1";
+ }
+ if ((localStorage["loadcount"]<=2) && (localStorage["bothered2"]!="1")) {
+ localStorage["bothered2"]="1";
+ }
if (localStorage["stbb"]=="on") {
localStorage["stbb"] = "flip";
}
@@ -44,11 +51,12 @@
chrome.tabs.create({url:'/options.html',selected:false});
}
+// Counts number of times Chrome has been opened to load donation message after certain amount
loadcount=localStorage["loadcount"];
loadcount++;
localStorage["loadcount"]=loadcount;
-// Message passer to give [LocalStorage] settings to content_script.js which is not allowed access to [LocalStorage].
+// Message passer to give [LocalStorage] settings to content_script.js because it is not allowed access to [LocalStorage]
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
if (request.greeting == "settings")
@@ -61,4 +69,5 @@
-</script>
+</script>
+<script src="context_menu.js"></script>
View
580 content_script.js
@@ -2,338 +2,312 @@
* Scroll to Top Button
* by Cody Sherman, http://codysherman.com/
*
-* Copyright (c) 2010 Cody Sherman
+* Copyright (c) 2011 Cody Sherman
* Licensed under the MIT License http://www.opensource.org/licenses/mit-license.php
*
-* Description: Scroll to Top Button allows you to quickly jump back to the top of any page! Once you scroll far enough down on a page, the button will appear in the top right corner. Click it, and you will be taken to the very top in no time!
+* Description: Scroll to Top Button allows you to quickly jump back to the top of any page! Once you scroll far enough down on a page, the button will appear in the top right corner. Click it, and you will be taken to the very top!
*
* To install: https://chrome.google.com/webstore/detail/chiikmhgllekggjhdfjhajkfdkcngplp
*
*Source code at: http://github.com/codysherman/Scroll-to-Top-Button-Extension
*
-*Version: 4.6.3
+*Version: 5.0.0
-----------------------*/
-
-STTB();
-
-// Checks if the URL already has built-in button.
-if (window.location.href.indexOf('http://www.tumblr.com/') != -1) {
- if (window.location.href.indexOf('http://www.tumblr.com/dashboard') != -1) {
- $('#return_to_top').remove();
- }
- else if (window.location.href.indexOf('http://www.tumblr.com/tumblelog/') != -1) {
- $('#return_to_top').remove();
- }
- else if (window.location.href.indexOf('http://www.tumblr.com/messages') != -1) {
- $('#return_to_top').remove();
- }
- else if (window.location.href.indexOf('http://www.tumblr.com/tagged/') != -1) {
- $('#return_to_top').remove();
- }
- else if (window.location.href.indexOf('http://www.tumblr.com/liked/by/') != -1) {
- $('#return_to_top').remove();
- }
- else if (window.location.href.indexOf('http://www.tumblr.com/likes') != -1) {
- $('#return_to_top').remove();
- }
+// Checks to see if page is larger than window, otherwise runs watch();
+if ((window == top) && ($(window).height()<$(document).height())) {
+ CheckIt();
}
-
-if (window.location.href.indexOf('http://scrolltotopbutton.tumblr.com/donationcompleted') != -1) {
- chrome.extension.sendRequest({greeting: "donated"});
+else {
+ watch();
}
-function STTB() {
-// Asks background.html for [LocalStorage] settings.
-chrome.extension.sendRequest({greeting: "settings"}, function(response) {
-var speed = parseInt(response.speed);
-var speed2 = parseInt(response.speed2);
-var distance = parseInt(response.distance);
-var flipDistance = parseInt(response.distance);
-var size = response.size;
-var arrow = response.arrow;
-var scroll = response.scroll;
-var location = response.location;
-var stbb = response.stbb;
-var transparency = response.transparency;
-
-if (stbb == "dual"){
-var imgURL=chrome.extension.getURL("arrows/dual/"+arrow+".png");
-}
-else{
-var imgURL=chrome.extension.getURL("arrows/"+arrow+".png");
+// Checks to see if the page changes size later or if a mistake was made judging size by user scrolling
+function watch(){
+ $(window).scroll(function () {
+ STTB();
+ $(window).unbind('scroll');
+ });
}
-// Actually creates the button on the page.
- $("body").prepend('<img id=STTBimg />');
- if(stbb=="flip"){
- $("#STTBimg").rotate(-180);
- };
-STTBimg.style.opacity = transparency;
-STTBimg.src=imgURL;
-STTBimg.style.position = 'fixed';
-STTBimg.style.width = size;
-STTBimg.style.height = 'auto';
-STTBimg.style.display = 'none';
-STTBimg.style.zIndex = 2147483647;
-STTBimg.style.border = '0px';
-STTBimg.style.padding = '0px';
-if (location == "TR") {
- STTBimg.style.top = '20px';
- STTBimg.style.right = '20px';
- STTBimg.style.margin = '0px 0px 0px 0px';
- }
-else if (location == "TL") {
- STTBimg.style.top = '20px';
- STTBimg.style.left = '20px';
- STTBimg.style.margin = '0px 0px 0px 0px';
- }
-else if ((location == "BR") && (stbb != "dual")) {
- STTBimg.style.bottom = '20px';
- STTBimg.style.right = '20px';
- STTBimg.style.margin = '0px 0px 0px 0px';
- }
-else if ((location == "BR") && (stbb == "dual")) {
- adjust=parseInt(size) / 2 + 22;
- adjusted=adjust + "px";
- STTBimg.style.bottom = adjusted;
- STTBimg.style.right = '20px';
- STTBimg.style.margin = '0px 0px 0px 0px';
- }
-else if ((location == "BL") && (stbb != "dual")) {
- STTBimg.style.bottom = '20px';
- STTBimg.style.left = '20px';
- STTBimg.style.margin = '0px 0px 0px 0px';
- }
-else if ((location == "BL") && (stbb == "dual")) {
- adjust=parseInt(size) / 2 + 22;
- adjusted=adjust + "px";
- STTBimg.style.bottom = adjusted;
- STTBimg.style.left = '20px';
- STTBimg.style.margin = '0px 0px 0px 0px';
- }
-else if (location == "CR") {
- adjust="-" + parseInt(size) / 2 + "px 0px 0px 0px";
- STTBimg.style.right = '20px';
- STTBimg.style.top = '50%';
- STTBimg.style.margin = adjust;
- }
-else if (location == "CL") {
- adjust="-" + parseInt(size) / 2 + "px 0px 0px 0px";
- STTBimg.style.left = '20px';
- STTBimg.style.top = '50%';
- STTBimg.style.margin = adjust;
- }
-else if (location == "TC") {
-
- adjust="0px -" + parseInt(size) / 2 + "px 0px 0px";
- STTBimg.style.top = '20px';
- STTBimg.style.right = '50%';
- STTBimg.style.margin = adjust;
- }
-else if ((location == "BC") && (stbb != "dual")) {
- adjust="0px -" + parseInt(size) / 2 + "px 0px 0px";
- STTBimg.style.bottom = '20px';
- STTBimg.style.right = '50%';
- STTBimg.style.margin = adjust;
- }
-else if ((location == "BC") && (stbb == "dual")) {
- adjust="0px -" + parseInt(size) / 2 + "px " + "0px 0px";
- adjust2=parseInt(size) / 2 + 22;
- adjusted=adjust2 + "px";
- STTBimg.style.bottom = adjusted;
- STTBimg.style.right = '50%';
- STTBimg.style.margin = adjust;
- }
-
-if(stbb=="dual"){
- $("body").prepend('<img id=STTBimg2 />');
- $("#STTBimg2").rotate(-180);
-STTBimg2.style.opacity = transparency;
-STTBimg2.src=imgURL;
-STTBimg2.style.position = 'fixed';
-STTBimg2.style.width = size;
-STTBimg2.style.height = 'auto';
-STTBimg2.style.display = 'none';
-STTBimg2.style.zIndex = 2147483647;
-STTBimg2.style.border = '0px';
-STTBimg2.style.padding = '0px';
-if (location == "TR") {
- adjust=parseInt(size) / 2 + 22;
- adjusted=adjust + "px";
- STTBimg2.style.top = adjusted;
- STTBimg2.style.right = '20px';
- STTBimg2.style.margin = '0px 0px 0px 0px';
- }
-else if (location == "TL") {
- adjust=parseInt(size) / 2 + 22;
- adjusted=adjust + "px";
- STTBimg2.style.top = adjusted;
- STTBimg2.style.left = '20px';
- STTBimg2.style.margin = '0px 0px 0px 0px';
- }
-else if (location == "BR") {
- STTBimg2.style.bottom = '20px';
- STTBimg2.style.right = '20px';
- STTBimg2.style.margin = '0px 0px 0px 0px';
- }
-else if (location == "BL") {
- STTBimg2.style.bottom = '20px';
- STTBimg2.style.left = '20px';
- STTBimg2.style.margin = '0px 0px 0px 0px';
- }
-else if (location == "CR") {
- adjust=2 + "px 0px 0px 0px";
- STTBimg2.style.right = '20px';
- STTBimg2.style.top = '50%';
- STTBimg2.style.margin = adjust;
- }
-else if (location == "CL") {
- adjust=2 + "px 0px 0px 0px";
- STTBimg2.style.left = '20px';
- STTBimg2.style.top = '50%';
- STTBimg2.style.margin = adjust;
- }
-else if (location == "TC") {
- adjust=parseInt(size) / 2 + 2 + "px -" + parseInt(size) / 2 + "px 0px 0px";
- STTBimg2.style.top = '20px';
- STTBimg2.style.right = '50%';
- STTBimg2.style.margin = adjust;
- }
-else if (location == "BC") {
- adjust="0px -" + parseInt(size) / 2 + "px 0px 0px";
- STTBimg2.style.bottom = '20px';
- STTBimg2.style.right = '50%';
- STTBimg2.style.margin = adjust;
- }
-
+// CheckIt() is a blacklist of websites that use frames and don't scroll as expected
+function CheckIt() {
+ var blockedUrlArray=['mail.google.com/','docs.google.com/','docs0.google.com/','google.com/calendar','spreadsheets.google.com/','spreadsheets0.google.com/'];
+ var urlArrayMatch;
+ $.each( blockedUrlArray, function(i, urlString){
+ if (window.location.href.indexOf( urlString ) != -1) {
+ urlArrayMatch=true;
+ return true; // break out of loop if match found
+ }
+ })
+ if( ! urlArrayMatch ){
+ STTB();
+ }
}
-if((stbb=="flip") || (stbb=="dual")){distance=0;CheckIt();};
-
-if (stbb != "keys"){
-var head = document.getElementsByTagName('head')[0],
- style = document.createElement('style'),
- rules = document.createTextNode('@media print{#STTBimg{ display:none; }#STTBimg2{ display:none; }}');
-
-style.type = 'text/css';
-style.appendChild(rules);
-head.appendChild(style);
-
-if ((transparency == 0.0) && (stbb=="dual")){
-$("#STTBimg").hover(function(){
- if($(window).scrollTop()>=distance){
-$("#STTBimg").stop();
-$("#STTBimg2").stop();
-$("#STTBimg").stop().fadeTo("fast", 1.0);
-$("#STTBimg2").stop().fadeTo("fast", 0.5);
+// Checks to see if person donates, to disable the message asking for donation later.
+if (window.location.href.indexOf('http://scrolltotopbutton.tumblr.com/donationcompleted') != -1) {
+ chrome.extension.sendRequest({greeting: "donated"});
}
- },function(){
- if($(window).scrollTop()>=distance){$("#STTBimg").stop().fadeTo("medium", transparency);$("#STTBimg2").stop().fadeTo("medium", transparency);}
- });
-$("#STTBimg2").hover(function(){
- if($(window).scrollTop()>=distance){
-$("#STTBimg").stop();
-$("#STTBimg2").stop();
-$("#STTBimg").stop().fadeTo("fast", 0.5);
-$("#STTBimg2").stop().fadeTo("fast", 1.0);
-}
- },function(){
- if($(window).scrollTop()>=distance){$("#STTBimg").fadeTo("medium", transparency);$("#STTBimg2").fadeTo("medium", transparency);}
- });
-}
+// Main function, sets up the button
+function STTB() {
+ // Removes the built-in button when on Tumblr
+ if (window.location.href.indexOf('http://www.tumblr.com/') != -1) {
+ var alreadyHasIt=['http://www.tumblr.com/dashboard','http://www.tumblr.com/tumblelog/','http://www.tumblr.com/messages','http://www.tumblr.com/tagged/','http://www.tumblr.com/liked/by/','http://www.tumblr.com/likes'];
+ $.each( alreadyHasIt, function(i, urlString){
+ if (window.location.href.indexOf( urlString ) != -1) {
+ $('#return_to_top').remove();
+ }
+ })
+ }
-else{
-$("#STTBimg").hover(function(){
- if($(window).scrollTop()>=distance){$("#STTBimg").stop().fadeTo("fast", 1.0);}
- },function(){
- if($(window).scrollTop()>=distance){$("#STTBimg").stop().fadeTo("medium", transparency);}
- });
+ // Asks background.html for [LocalStorage] settings from Options Page and assigns them to variables
+ chrome.extension.sendRequest({greeting: "settings"}, function(response) {
+ var speed = parseInt(response.speed);
+ var speed2 = parseInt(response.speed2);
+ var distance = parseInt(response.distance);
+ var flipDistance = parseInt(response.distance);
+ var size = response.size;
+ var arrow = response.arrow;
+ var scroll = response.scroll;
+ var location = response.location;
+ var stbb = response.stbb;
+ var transparency = response.transparency;
-$("#STTBimg2").hover(function(){
- if($(window).scrollTop()>=distance){$("#STTBimg2").stop().fadeTo("fast", 1.0);}
- },function(){
- if($(window).scrollTop()>=distance){$("#STTBimg2").stop().fadeTo("medium", transparency);}
- });
-}
+ // Assigns the correct arrow color to imgURL
+ if (stbb == "dual"){
+ var imgURL=chrome.extension.getURL("arrows/dual/"+arrow+".png");
+ }
+ else{
+ var imgURL=chrome.extension.getURL("arrows/"+arrow+".png");
+ }
+ // Creates the button image on the page
+ $("body").prepend('<img id=STTBimg />');
+ if(stbb=="flip"){
+ $("#STTBimg").rotate(-180);
+ };
+ STTBimg.style.opacity = transparency;
+ STTBimg.src=imgURL;
+ STTBimg.style.position = 'fixed';
+ STTBimg.style.width = size;
+ STTBimg.style.height = 'auto';
+ STTBimg.style.display = 'none';
+ STTBimg.style.zIndex = 2147483647;
+ STTBimg.style.border = '0px';
+ STTBimg.style.padding = '0px';
+ if (location == "TR") {
+ STTBimg.style.top = '20px';
+ STTBimg.style.right = '20px';
+ STTBimg.style.margin = '0px 0px 0px 0px';
+ }
+ else if (location == "TL") {
+ STTBimg.style.top = '20px';
+ STTBimg.style.left = '20px';
+ STTBimg.style.margin = '0px 0px 0px 0px';
+ }
+ else if ((location == "BR") && (stbb != "dual")) {
+ STTBimg.style.bottom = '20px';
+ STTBimg.style.right = '20px';
+ STTBimg.style.margin = '0px 0px 0px 0px';
+ }
+ else if ((location == "BR") && (stbb == "dual")) {
+ adjust=parseInt(size) / 2 + 22;
+ adjusted=adjust + "px";
+ STTBimg.style.bottom = adjusted;
+ STTBimg.style.right = '20px';
+ STTBimg.style.margin = '0px 0px 0px 0px';
+ }
+ else if ((location == "BL") && (stbb != "dual")) {
+ STTBimg.style.bottom = '20px';
+ STTBimg.style.left = '20px';
+ STTBimg.style.margin = '0px 0px 0px 0px';
+ }
+ else if ((location == "BL") && (stbb == "dual")) {
+ adjust=parseInt(size) / 2 + 22;
+ adjusted=adjust + "px";
+ STTBimg.style.bottom = adjusted;
+ STTBimg.style.left = '20px';
+ STTBimg.style.margin = '0px 0px 0px 0px';
+ }
+ else if (location == "CR") {
+ adjust="-" + parseInt(size) / 2 + "px 0px 0px 0px";
+ STTBimg.style.right = '20px';
+ STTBimg.style.top = '50%';
+ STTBimg.style.margin = adjust;
+ }
+ else if (location == "CL") {
+ adjust="-" + parseInt(size) / 2 + "px 0px 0px 0px";
+ STTBimg.style.left = '20px';
+ STTBimg.style.top = '50%';
+ STTBimg.style.margin = adjust;
+ }
+ else if (location == "TC") {
+ adjust="0px -" + parseInt(size) / 2 + "px 0px 0px";
+ STTBimg.style.top = '20px';
+ STTBimg.style.right = '50%';
+ STTBimg.style.margin = adjust;
+ }
+ else if ((location == "BC") && (stbb != "dual")) {
+ adjust="0px -" + parseInt(size) / 2 + "px 0px 0px";
+ STTBimg.style.bottom = '20px';
+ STTBimg.style.right = '50%';
+ STTBimg.style.margin = adjust;
+ }
+ else if ((location == "BC") && (stbb == "dual")) {
+ adjust="0px -" + parseInt(size) / 2 + "px " + "0px 0px";
+ adjust2=parseInt(size) / 2 + 22;
+ adjusted=adjust2 + "px";
+ STTBimg.style.bottom = adjusted;
+ STTBimg.style.right = '50%';
+ STTBimg.style.margin = adjust;
+ }
-// Calls, and passes variables to jquery.scroll.pack.js which finds the created button and applies the scrolling rules.
- $("#STTBimg").scrollToTop({speed:speed, ease:scroll, start:distance, stbb:stbb, flipDistance:flipDistance, transparency:transparency, direction:"up"});
- $("#STTBimg2").scrollToTop({speed:speed2, ease:scroll, start:distance, stbb:stbb, flipDistance:flipDistance, transparency:transparency, direction:"down"});
+ if(stbb=="dual"){
+ $("body").prepend('<img id=STTBimg2 />');
+ $("#STTBimg2").rotate(-180);
+ STTBimg2.style.opacity = transparency;
+ STTBimg2.src=imgURL;
+ STTBimg2.style.position = 'fixed';
+ STTBimg2.style.width = size;
+ STTBimg2.style.height = 'auto';
+ STTBimg2.style.display = 'none';
+ STTBimg2.style.zIndex = 2147483647;
+ STTBimg2.style.border = '0px';
+ STTBimg2.style.padding = '0px';
+ if (location == "TR") {
+ adjust=parseInt(size) / 2 + 22;
+ adjusted=adjust + "px";
+ STTBimg2.style.top = adjusted;
+ STTBimg2.style.right = '20px';
+ STTBimg2.style.margin = '0px 0px 0px 0px';
+ }
+ else if (location == "TL") {
+ adjust=parseInt(size) / 2 + 22;
+ adjusted=adjust + "px";
+ STTBimg2.style.top = adjusted;
+ STTBimg2.style.left = '20px';
+ STTBimg2.style.margin = '0px 0px 0px 0px';
+ }
+ else if (location == "BR") {
+ STTBimg2.style.bottom = '20px';
+ STTBimg2.style.right = '20px';
+ STTBimg2.style.margin = '0px 0px 0px 0px';
+ }
+ else if (location == "BL") {
+ STTBimg2.style.bottom = '20px';
+ STTBimg2.style.left = '20px';
+ STTBimg2.style.margin = '0px 0px 0px 0px';
+ }
+ else if (location == "CR") {
+ adjust=2 + "px 0px 0px 0px";
+ STTBimg2.style.right = '20px';
+ STTBimg2.style.top = '50%';
+ STTBimg2.style.margin = adjust;
+ }
+ else if (location == "CL") {
+ adjust=2 + "px 0px 0px 0px";
+ STTBimg2.style.left = '20px';
+ STTBimg2.style.top = '50%';
+ STTBimg2.style.margin = adjust;
+ }
+ else if (location == "TC") {
+ adjust=parseInt(size) / 2 + 2 + "px -" + parseInt(size) / 2 + "px 0px 0px";
+ STTBimg2.style.top = '20px';
+ STTBimg2.style.right = '50%';
+ STTBimg2.style.margin = adjust;
+ }
+ else if (location == "BC") {
+ adjust="0px -" + parseInt(size) / 2 + "px 0px 0px";
+ STTBimg2.style.bottom = '20px';
+ STTBimg2.style.right = '50%';
+ STTBimg2.style.margin = adjust;
+ }
+ }
-} //Keyboard Only
-
- shortcut.add("Alt+B", function() {
- DOWN(speed2, scroll);
- });
- shortcut.add("End", function() {
- DOWN(speed2, scroll);
- },{
- 'disable_in_input':true
- });
- shortcut.add("Alt+T", function() {
- UP(speed, scroll);
- });
- shortcut.add("Home", function() {
- UP(speed, scroll);
- },{
- 'disable_in_input':true
- });
+ // Sets the appear distance to 0 for modes where button is always present
+ if((stbb=="flip") || (stbb=="dual")){
+ distance=0;
+ };
- });
+ // Creates CSS so that the button is not present on printed pages
+ if (stbb != "keys"){
+ var head = document.getElementsByTagName('head')[0],
+ style = document.createElement('style'),
+ rules = document.createTextNode('@media print{#STTBimg{ display:none; }#STTBimg2{ display:none; }}');
-function CheckIt() {
-$(document).ready(function($) {
- if ((window == top) && ($(window).height()>=$(document).height())) {
- REMOVE();
- }
- else if (window.location.href.indexOf('mail.google.com/') != -1) {
- REMOVE();
- }
- else if (window.location.href.indexOf('docs.google.com/') != -1) {
- REMOVE();
- }
- else if (window.location.href.indexOf('docs0.google.com/') != -1) {
- REMOVE();
- }
- else if (window.location.href.indexOf('google.com/calendar') != -1) {
- REMOVE();
- }
- else if (window.location.href.indexOf('spreadsheets.google.com/') != -1) {
- REMOVE();
- }
- else if (window.location.href.indexOf('spreadsheets0.google.com/') != -1) {
- REMOVE();
- }
+ style.type = 'text/css';
+ style.appendChild(rules);
+ head.appendChild(style);
+ };
-function REMOVE() {
-$('#STTBimg').fadeTo('medium', 0.0, function() {
- $(this).remove();
-});
-$('#STTBimg2').fadeTo('medium', 0.0, function() {
- $(this).remove();
-});
-watch();
-};
+ // A fix so that if user has set transparency to 0, both buttons will appear when hovering over one in dual mode
+ if ((transparency == 0.0) && (stbb=="dual")){
+ $("#STTBimg").hover(function(){
+ if($(window).scrollTop()>=distance){
+ $("#STTBimg").stop();
+ $("#STTBimg2").stop();
+ $("#STTBimg").stop().fadeTo("fast", 1.0);
+ $("#STTBimg2").stop().fadeTo("fast", 0.5);
+ }
+ },function(){
+ if($(window).scrollTop()>=distance){
+ $("#STTBimg").stop().fadeTo("medium", transparency);$("#STTBimg2").stop().fadeTo("medium", transparency);
+ }
+ });
-function watch(){
- var scrolled = 0;
- $(window).scroll(function () {
- if (scrolled==0) {
- STTB();
- scrolled = 1;
- };
- });
+ $("#STTBimg2").hover(function(){
+ if($(window).scrollTop()>=distance){
+ $("#STTBimg").stop();
+ $("#STTBimg2").stop();
+ $("#STTBimg").stop().fadeTo("fast", 0.5);
+ $("#STTBimg2").stop().fadeTo("fast", 1.0);
+ }
+ },function(){
+ if($(window).scrollTop()>=distance){
+ $("#STTBimg").fadeTo("medium", transparency);$("#STTBimg2").fadeTo("medium", transparency);
+ }
+ });
+ }
+ // Has transparency change on mouseover
+ else{
+ if (transparency != 1.0) {
+ $("#STTBimg").hover(function(){
+ if($(window).scrollTop()>=distance){$("#STTBimg").stop().fadeTo("fast", 1.0);}
+ },function(){
+ if($(window).scrollTop()>=distance){$("#STTBimg").stop().fadeTo("medium", transparency);}
+ });
-};
+ $("#STTBimg2").hover(function(){
+ if($(window).scrollTop()>=distance){$("#STTBimg2").stop().fadeTo("fast", 1.0);}
+ },function(){
+ if($(window).scrollTop()>=distance){$("#STTBimg2").stop().fadeTo("medium", transparency);}
+ });
+ }
+ }
-});
-};
+ // Calls and passes variables to jquery.scroll.pack.js which finds the created button and applies the scrolling rules.
+ $("#STTBimg").scrollToTop({speed:speed, ease:scroll, start:distance, stbb:stbb, flipDistance:flipDistance, transparency:transparency, direction:"up"});
+ $("#STTBimg2").scrollToTop({speed:speed2, ease:scroll, start:distance, stbb:stbb, flipDistance:flipDistance, transparency:transparency, direction:"down"});
+ //Adds keyboard commands using shortcut.js
+ shortcut.add("Alt+B", function() {
+ DOWN(speed2, scroll);
+ });
+ shortcut.add("Alt+T", function() {
+ UP(speed, scroll);
+ });
+ shortcut.add("End", function() {
+ DOWN(speed2, scroll);
+ },{
+ 'disable_in_input':true
+ });
+ shortcut.add("Home", function() {
+ UP(speed, scroll);
+ },{
+ 'disable_in_input':true
+ });
+ });
};
-
-
-
View
13 context_menu.js
@@ -0,0 +1,13 @@
+// A generic onclick callback function.
+function genericOnClick(info, tab) {
+chrome.tabs.create({url:'/options.html'});
+}
+
+// Creates context menu
+if (localStorage["contextmenu"]=="on") {
+ var contexts = ["page","image"];
+ for (var i = 0; i < contexts.length; i++) {
+ var context = contexts[i];
+ var id = chrome.contextMenus.create({ "title": 'Scroll To Top Button Options', "contexts": [context], "onclick": genericOnClick });
+ }
+}
View
228 jquery.scroll.pack.js
@@ -8,114 +8,134 @@
* Description: Adds an unobtrusive "Scroll to Top" link to your page with smooth scrolling.
* For usage instructions and version updates to go http://blog.ph-creative.com/post/jquery-plugin-scroll-to-top-v3.aspx
*
-* Version: 3.1, 29/07/2010
------------------------*/
+* Version: 3.1, 29/07/2010
+*
+* Modified for Scroll to Top Button by Cody Sherman
+* http://codysherman.com/
+*
+* Modified for version 5.0.0
+-----------------------*/
+// Functions for going either UP or DOWN
function UP(speed,ease){
-$("html, body").animate({scrollTop:"0"},speed,ease,function() {inProgress="no"});
+ $("html, body").animate({scrollTop:"0"},speed,ease,function() {inProgress="no"});
}
function DOWN(speed,ease){
-$("html, body").animate({scrollTop:$(document).height()},speed,ease,function() {inProgress="no"});
+ $("html, body").animate({scrollTop:$(document).height()},speed,ease,function() {inProgress="no"});
}
+
+// Craig's Scroll to Top Plugin with modifications
(function($){
- $.fn.extend({scrollToTop:function(options){
+ $.fn.extend({
+ scrollToTop:function(options){
- var defaults={speed:"slow",ease:"jswing",start:0}
+ var defaults={speed:"slow",ease:"jswing",start:0}
- var options=$.extend(defaults,options);
-
- return this.each(function(){var o=options;var scrollDiv=$(this);
-
- $(this).hide().removeAttr("href").css("cursor","pointer");
-
- if(o.stbb=="flip"){
- if($(window).scrollTop()>=o.flipDistance){
- $("#STTBimg").rotateAnimation(0);
- o.direction="up";
- };
-
- if($(window).scrollTop()<"200"){
- $("#STTBimg").rotateAnimation(-180);
- o.direction="down";
- };
-};
-
- if($(window).scrollTop()>=o.start){
-
- $(this).fadeIn("slow");}$(window).scroll(function(){
-
- if($(window).scrollTop()>=o.start){
- $(scrollDiv).fadeIn("slow");}else{
- $(scrollDiv).fadeOut("slow");
- }
-
-if(o.stbb=="flip"){
- if($(window).scrollTop()>=o.flipDistance){
- $("#STTBimg").rotateAnimation(0);
- o.direction="up";
- };
-
- if($(window).scrollTop()<o.flipDistance){
- $("#STTBimg").rotateAnimation(-180);
- o.direction="down";
- };
-};
-
-});
-
-inProgress="no";
-
-if((o.stbb=="flip") || (o.stbb=="dual")){
- scrollDiv.click(function(event){
- if(inProgress=="yes"){
- $("html, body").stop();
- inProgress="no";
- }
-
- else if(o.direction=="up"){
- inProgress="yes";
- speed=o.speed;
- ease=o.ease;
- UP(speed,ease);
- if((o.transparency=="0.0")&&(o.stbb=="dual")){
- $(this).fadeTo("medium", 0.5);
- }
- else{
- $(this).fadeTo("medium", o.transparency);
- }
- }
-
- else if(o.direction=="down"){
- inProgress="yes";
- speed=o.speed;
- ease=o.ease;
- DOWN(speed,ease);
- if((o.transparency=="0.0")&&(o.stbb=="dual")){
- $(this).fadeTo("medium", 0.5);
- }
- else{
- $(this).fadeTo("medium", o.transparency);
- }
- }
- })
-}
-
-else if(o.stbb=="off"){
- scrollDiv.click(function(event){
- if(inProgress=="yes"){
- $("html, body").stop();
- inProgress="no";
- }
-
- else{
- inProgress="yes";
- speed=o.speed;
- ease=o.ease;
- UP(speed,ease);
- }
- })
-}
-
-});
-}
-});
-})(jQuery);
+ var options=$.extend(defaults,options);
+
+ return this.each(function(){
+
+ var o=options;var scrollDiv=$(this);
+
+ $(this).hide().removeAttr("href").css("cursor","pointer");
+
+ // Allows the button to change directions when in "Flip" mode on page load
+ if(o.stbb=="flip"){
+ if($(window).scrollTop()>=o.flipDistance){
+ $("#STTBimg").rotateAnimation(0);
+ o.direction="up";
+ };
+
+ if($(window).scrollTop()<"200"){
+ $("#STTBimg").rotateAnimation(-180);
+ o.direction="down";
+ };
+ };
+
+ // Checks whether button should be visable at page load
+ if($(window).scrollTop()>=o.start){
+ $(this).fadeIn("slow");
+ }
+
+ // Checks whether button should be visable/flipped on scroll
+ $(window).scroll(function(){
+ if($(window).scrollTop()>=o.start){
+ $(scrollDiv).fadeIn("slow");
+ }else{
+ $(scrollDiv).fadeOut("slow");
+ }
+
+ if(o.stbb=="flip"){
+ if($(window).scrollTop()>=o.flipDistance){
+ $("#STTBimg").rotateAnimation(0);
+ o.direction="up";
+ };
+
+ if($(window).scrollTop()<o.flipDistance){
+ $("#STTBimg").rotateAnimation(-180);
+ o.direction="down";
+ };
+ };
+ });
+
+ inProgress="no";
+
+ //Rules specific to the button when it is bi-directional
+ if((o.stbb=="flip") || (o.stbb=="dual")){
+ scrollDiv.click(function(event){
+
+ // Stops the scrolling if button is clicked a second time.
+ if(inProgress=="yes"){
+ $("html, body").stop();
+ inProgress="no";
+ }
+
+ // Runs the proper scroll direction function
+ else if(o.direction=="up"){
+ inProgress="yes";
+ speed=o.speed;
+ ease=o.ease;
+ UP(speed,ease);
+ if((o.transparency=="0.0")&&(o.stbb=="dual")){
+ $(this).fadeTo("medium", 0.5);
+ }
+ else{
+ $(this).fadeTo("medium", o.transparency);
+ }
+ }
+
+ else if(o.direction=="down"){
+ inProgress="yes";
+ speed=o.speed;
+ ease=o.ease;
+ DOWN(speed,ease);
+ if((o.transparency=="0.0")&&(o.stbb=="dual")){
+ $(this).fadeTo("medium", 0.5);
+ }
+ else{
+ $(this).fadeTo("medium", o.transparency);
+ }
+ }
+ })
+ }
+
+ // Sets up the scrolling rules when in only Scroll to Top mode
+ else if(o.stbb=="off"){
+ scrollDiv.click(function(event){
+ if(inProgress=="yes"){
+ $("html, body").stop();
+ inProgress="no";
+ }
+
+ else{
+ inProgress="yes";
+ speed=o.speed;
+ ease=o.ease;
+ UP(speed,ease);
+ }
+ })
+ }
+ });
+ }
+ });
+})
+(jQuery);
View
8 manifest.json
@@ -1,7 +1,7 @@
{
- "name": "Scroll to Top Button",
- "version": "4.7",
- "description": "Adds a scroll to top/bottom button.",
+ "name": "Scroll To Top Button",
+ "version": "5.0",
+ "description": "Adds a scroll to top or bottom button.",
"icons": {"16": "icons/icon16.png",
"32": "icons/icon32.png",
"48": "icons/icon48.png",
@@ -12,6 +12,6 @@
{ "matches": ["<all_urls>"], "js": ["libraries/jquery-1.5.min.js", "libraries/jquery.easing.js", "libraries/jQueryRotate.js", "jquery.scroll.pack.js", "content_script.js", "libraries/shortcut.js"] }
],
"permissions": [
- "tabs"
+ "tabs", "contextMenus"
]
}
View
79 options.html
@@ -1,5 +1,5 @@
<html>
-<head><title>Scroll to Top Button Options</title>
+<head><title>Scroll To Top Button Options</title>
<link rel="stylesheet" type="text/css" href="/style.css">
@@ -12,10 +12,12 @@
function defaults() {
loadcount=localStorage["loadcount"];
donated=localStorage["donated"];
- bothered=localStorage["bothered"];
+ bothered=localStorage["bothered"];
+ bothered2=localStorage["bothered2"];
localStorage.clear();
localStorage["loadcount"]=loadcount;
localStorage["bothered"]=bothered;
+ localStorage["bothered2"]=bothered2;
localStorage["donated"]=donated;
localStorage["latest"]="2";
restore_options();
@@ -23,6 +25,7 @@
textChange();
}
+// Sets options to my personal setup
function authorsettings() {
localStorage["scroll_speed"]="1000";
localStorage["scroll_speed2"]="1000";
@@ -30,7 +33,8 @@
localStorage["arrow"]="arrow_only_blue";
localStorage["location"]="CR";
localStorage["stbb"]="dual";
- localStorage["transparency"]="0.5";
+ localStorage["transparency"]="0.5";
+ localStorage["contextmenu"]="on";
restore_options();
save_options();
textChange();
@@ -72,7 +76,11 @@
var select = document.getElementById("transparency");
var transparency = select.children[select.selectedIndex].value;
- localStorage["transparency"] = transparency;
+ localStorage["transparency"] = transparency;
+
+ var select = document.getElementById("contextmenu");
+ var contextmenu = select.children[select.selectedIndex].value;
+ localStorage["contextmenu"] = contextmenu;
// Update status to let user know options were saved.
var status = document.getElementById("status");
@@ -80,6 +88,22 @@
setTimeout(function() {
status.innerHTML = "";
}, 3000);
+}
+
+// Message to restart Chrome when setting change requires it
+var restartChange = "false";
+function restart() {
+ if (restartChange=="false") {
+ var status = document.getElementById("restartstatus");
+ status.innerHTML = "Restart Google Chrome to take effect.";
+ restartChange = "true";
+ }
+ else if (restartChange=="true") {
+ var status = document.getElementById("restartstatus");
+ status.innerHTML = "";
+ restartChange = "false";
+ }
+
}
// Restores select box state to saved value from localStorage.
@@ -96,14 +120,14 @@
break;
}
}
- var favorite = localStorage["scroll_speed2"];
- if (!favorite) {
- favorite = 1000;
+ var favorite9 = localStorage["scroll_speed2"];
+ if (!favorite9) {
+ favorite9 = 1000;
}
var select = document.getElementById("speed2");
for (var i = 0; i < select.children.length; i++) {
var child = select.children[i];
- if (child.value == favorite) {
+ if (child.value == favorite9) {
child.selected = "true";
break;
}
@@ -191,6 +215,18 @@
child.selected = "true";
break;
}
+ }
+ var favorite10 = localStorage["contextmenu"];
+ if (!favorite10) {
+ favorite10 = "on";
+ }
+ var select = document.getElementById("contextmenu");
+ for (var i = 0; i < select.children.length; i++) {
+ var child = select.children[i];
+ if (child.value == favorite10) {
+ child.selected = "true";
+ break;
+ }
}
save_options();
}
@@ -224,6 +260,9 @@
else if (option == 9) {
_gaq.push(['_trackEvent', 'Scroll Speed Down', localStorage["scroll_speed2"]]);
}
+ else if (option == 10) {
+ _gaq.push(['_trackEvent', 'Context Menu', localStorage["contextmenu"]]);
+ }
}
function textChange(){
@@ -391,21 +430,29 @@
</select>
</div>
</p>
+<p><p style="float:left; margin-top:0px; padding-right:4px;">
+Context (Right-click) Menu:</p>
+<select id="contextmenu" style="float:left; margin-top:0px;" onChange="save_options();restart();report(10)">
+ <option value="on">On</option>
+ <option value="off">Off</option>
+</select>
+<p id="restartstatus" style="float:left; font-size:.9em; line-height:.5; margin-top:0px; padding:6px 0 0 10px;"></p>
+</p>
<script type="text/javascript">$(document).ready(textChange());</script>
-<button id="restore" onClick="defaults()"></button>
-<button id="author" onClick="authorsettings()"></button>
+<button id="restore" title="Restore Defaults" onClick="defaults()"></button>
+<button id="author" title="Author's Settings" onClick="authorsettings()"></button>
<p id="status" style="float:left; font-size:.9em; line-height:.5; padding:3px 0 0 10px;"></p>
-<p style="padding-top:50px;"><strong><center>Press Alt+T/Alt+B or Home/End on a page to scroll with just your keyboard!</center></strong></p>
+<p style="padding-top:10px;clear:left;"><strong><center>Press Alt+T/Alt+B or Home/End on a page to scroll with just your keyboard!</center></strong></p>
<!--<p><strong>Do you speak multiple languages? Please help me translate this extension! <a href="mailto:sttb@codysherman.com">Email me!</a></strong></p>-->
<div id="bottomNav">
-<a href="http://scrolltotopbutton.tumblr.com/" target="_blank"><div id="release"></div></a>
-<a href="http://github.com/codysherman/Scroll-to-Top-Button-Extension" target="_blank"><div id="source"></div></a>
-<a href="http://codysherman.com/" target="_blank"><div id="cody"></div></a>
+<a href="http://scrolltotopbutton.tumblr.com/" title="Release Notes" target="_blank"><div id="release"></div></a>
+<a href="http://github.com/codysherman/Scroll-to-Top-Button-Extension" title="Source Code" target="_blank"><div id="source"></div></a>
+<a href="http://codysherman.com/" title="By Cody Sherman" target="_blank"><div id="cody"></div></a>
</div>
<div style="border:1px #434b52 solid;height:60px;">
-<div style="float:left;padding-left:3px;width:440px;padding-top:3px;">A fan of Scroll to Top Button? Donate! You can donate whatever amount you would like, and I would appreciate anything I can get to help pay for college and stuffs :) <a href="http://scrolltotopbutton.tumblr.com/STTBdonate" target="_blank">Need convincing?</a></div>
+<div style="float:left;padding-left:3px;width:440px;padding-top:3px;">A fan of Scroll To Top Button? Donate! You can donate whatever amount you would like, and I would appreciate anything I can get to help pay for college and stuffs :) <a href="http://scrolltotopbutton.tumblr.com/donate" target="_blank">More reasons to donate!</a></div>
<div style="padding-top:12px;padding-left:10px;float:left;">
-<a href="http://scrolltotopbutton.tumblr.com/STTBdonate"><img src="/images/donate.png" alt="Donate"/></a>
+<a href="http://scrolltotopbutton.tumblr.com/donate" title="Donate Now" target="_blank"><img src="/images/donate.png" alt="Donate"/></a>
</div>
</div>
View
3  style.css
@@ -46,7 +46,8 @@ outline: none;
background-image:url(images/restore.png);
background-color:transparent;
background-position:0 0;
- float:left;
+ float:left;
+ clear:left;
border:none;
cursor: pointer;
}
Please sign in to comment.
Something went wrong with that request. Please try again.