forked from tomerweller/oogi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2201641
commit 64e1ef8
Showing
3 changed files
with
42 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,44 @@ | ||
var headElement = (document.head||document.documentElement); | ||
var actualCode = `var cookieGetter = document.__lookupGetter__("cookie").bind(document); | ||
var cookieSetter = document.__lookupSetter__("cookie").bind(document); | ||
var injectJs = function(fileName) { | ||
var s = document.createElement('script'); | ||
s.src = chrome.extension.getURL(fileName); | ||
headElement.insertBefore(s, headElement.firstElementChild); | ||
var getPrefix = function() { | ||
return "oogi$" | ||
}; | ||
injectJs("common.js"); | ||
injectJs("inject.js"); | ||
var processCookieStr = function(cookiesStr) { | ||
var prefix = getPrefix(); | ||
var cookieStrList = cookiesStr.split('; '); | ||
var newStrList = []; | ||
cookieStrList.forEach(function(cookieStr){ | ||
if (cookieStr.indexOf(prefix)==0) { | ||
newStrList.push(cookieStr.substring(prefix.length, cookieStr.length)); | ||
} | ||
}); | ||
return newStrList.join("; "); | ||
}; | ||
var processSetCookieStr = function(str) { | ||
console.log("Processing set cookie string " + str); | ||
return getPrefix()+str; | ||
}; | ||
Object.defineProperty(document, 'cookie', { | ||
get: function() { | ||
var storedCookieStr = cookieGetter(); | ||
console.log("Intercepted a cookie get " + storedCookieStr + " , and returning processed cookie string " + processCookieStr(storedCookieStr)); | ||
return processCookieStr(storedCookieStr); | ||
}, | ||
set: function(cookieString) { | ||
var newValue = processSetCookieStr(cookieString); | ||
console.log("Intercepted a cookie set " + newValue) | ||
return cookieSetter(newValue); | ||
} | ||
}); | ||
console.log("cookie get/set injector completed"); | ||
`; | ||
|
||
var script = document.createElement('script'); | ||
script.textContent = actualCode; | ||
(document.head||document.documentElement).appendChild(script); | ||
script.remove(); |