Skip to content
This repository has been archived by the owner on Sep 9, 2023. It is now read-only.

Updated the source to what is available in the chrome webstore #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions hotlink.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '']);
_gaq.push(['_setAccount', 'UA-105840655-2']);
_gaq.push(['_trackPageview']);

(function() {
Expand All @@ -11,6 +11,24 @@ _gaq.push(['_trackPageview']);
s.parentNode.insertBefore(ga, s);
})();

chrome.runtime.onInstalled.addListener(function(details){
var version = chrome.runtime.getManifest().version;

if( details.reason === 'update' ){
version = details.previousVersion + '->' + version;
}

_gaq.push(['_trackEvent', 'chrome::' + details.reason, version]);
});

var lastRequest = false;
setInterval(function(){
if( Date.now() - lastRequest < 265000 ){
_gaq.push(['_trackPageview']);
console.log('track view')
}
},270000);

chrome.webRequest.onBeforeSendHeaders.addListener(function(details){
var headers = details.requestHeaders;

Expand All @@ -35,22 +53,47 @@ chrome.webRequest.onBeforeSendHeaders.addListener(function(details){

return {'requestHeaders':headers};
},{urls: [ "<all_urls>" ]},['requestHeaders','blocking']);


var _request = {};
chrome.webRequest.onBeforeRequest.addListener(function(details){
lastRequest = Date.now();

var url = details.url;
var _id = 'i' + details.requestId;
var url = details.url;


if( url.match(/^.+\.wp\.com\/((?:.+\.)?photobucket\.com\/.+)/) ){
url = url.replace(/^.+\.wp\.com\/((?:.+\.)?photobucket\.com\/.+)/, 'https://$1');

return {redirectUrl: url};
}

if( url.match(/^.+proxy\.php\?image=((?:.+\.)?photobucket\.com.+)(?:&hash.*?)$/) ){
url = url.replace(/^.+proxy\.php\?image=((?:.+\.)?photobucket\.com.+)(?:&hash.*?)$/, '$1');
url = decodeURIComponent(url);
url = url.replace("http://","https://")

return {redirectUrl: decodeURIComponent(url)};
}

if( url.match(/photobucket/) ){
var pUrl = new URL(url);
if( !pUrl.searchParams.get('hotlinkfix') ){
var date = new Date().getTime();
pUrl.searchParams.set('hotlinkfix', date);

return {'redirectUrl': pUrl.href};
}

return {'redirectUrl': pUrl.href};
}
},{urls: [ "<all_urls>" ]},['blocking']);

chrome.webRequest.onCompleted.addListener(function(details){
// hotlinkAllowed[details.tabId] = false;

var _id = 'i' + details.requestId;
if( (_id in _request) ){
delete _request[_id];
}
},{urls: [ "<all_urls>" ]});