Skip to content

Commit

Permalink
Update to ver 4.0 which able to run on Chrome 73
Browse files Browse the repository at this point in the history
  • Loading branch information
HitomaruKonpaku committed Mar 20, 2019
1 parent c69aa70 commit 2352132
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 213 deletions.
8 changes: 4 additions & 4 deletions cdn/css/bootstrap.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cdn/css/vue-on-toast.min.css

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions cdn/js/bootstrap.min.js

This file was deleted.

4 changes: 2 additions & 2 deletions cdn/js/vue-on-toast.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cdn/js/vue.min.js

Large diffs are not rendered by default.

13 changes: 4 additions & 9 deletions manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Sad Panda",
"version": "3.1",
"version": "4.0",
"description": "Easy access to ExHentai",
"icons": {
"16": "ico/16.png",
Expand All @@ -24,15 +24,12 @@
],
"js": [
"cdn/js/jquery.min.js",
"cdn/js/bootstrap.min.js",
"cdn/js/vue.min.js",
"cdn/js/vue-on-toast.min.js",
"src/js/login.js"
],
"css": [
"cdn/css/bootstrap.min.css",
"cdn/css/vue-on-toast.min.css",
"src/css/login.css"
"cdn/css/vue-on-toast.min.css"
]
},
{
Expand All @@ -50,13 +47,11 @@
],
"permissions": [
"activeTab",
"contentSettings",
"cookies",
"tabs",
"notifications",
"*://exhentai.org/*",
"*://e-hentai.org/*",
"*://*.e-hentai.org/*",
"*://exhentai.org/*"
"*://*.e-hentai.org/*"
],
"web_accessible_resources": [
"cdn/*",
Expand Down
4 changes: 2 additions & 2 deletions src/css/logout.css
@@ -1,3 +1,3 @@
#haruhichanSignOut {
color: #DDD;
body #nb {
max-width: 720px;
}
4 changes: 2 additions & 2 deletions src/html/login.html
@@ -1,6 +1,6 @@
<div id="app" class="container">

<toast-container :toastConfig="toastCustomConfig"></toast-container>
<toast-container></toast-container>

<div>
<img src="https://exhentai.org/">
Expand All @@ -10,7 +10,7 @@

<div class="form-group">
<input v-model="username" id="username" class="form-control" type="text" placeholder="Username" required autofocus
:disabled="disabled">
:disabled="disabled" ref="username">
</div>

<div class="form-group">
Expand Down
125 changes: 83 additions & 42 deletions src/js/background.js
@@ -1,3 +1,57 @@
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
//
const action = String(message.action).toLowerCase().trim()
const data = Object(message.data)
// LOGIN
if (action === 'login') {
(async () => {
try {
//
const res = await fetch(data.url, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: data.data
})
//
const content = await res.text()
console.log(content)
// Success
if (content.includes('You are now logged in as')) {
sendResponse({ success: 'You are now logged in!' })
saveCookies()
reload()
return
}
// Fail
if (content.includes('Username or password incorrect')) {
sendResponse({ fail: 'Username or password incorrect!' })
} else if (content.includes('You must already have registered for an account before you can log in')) {
sendResponse({ fail: 'Username does not exist!' })
} else {
sendResponse({ fail: 'Error parsing login result page!' })
}
} catch (err) {
console.error(err)
sendResponse({ error: err.message })
}
})()
return true
}
// LOGOUT
if (action === 'logout') {
deleteCookies()
reload()
}
})

function reload() {
chrome.tabs.query({ active: true }, function (tabs) {
if (!tabs || !tabs.length) return
const id = tabs[0].id
chrome.tabs.reload(id)
})
}

function unixTime() {
return Math.round((new Date()).getTime() / 1000)
}
Expand All @@ -6,49 +60,36 @@ function cookieExpireTime() {
return unixTime() + 172800
}

function setHentaiCookies() {
try {
chrome.cookies.getAll({ domain: '.e-hentai.org' }, function (got) {
for (let i = 0; i < got.length; i++) {
if (got[i].name.indexOf('ipb_') != -1 || got[i].name.indexOf('uconfig') != -1) {
chrome.cookies.set({
url: 'https://exhentai.org/',
domain: '.exhentai.org', path: '/',
name: got[i].name,
value: got[i].value,
expirationDate: cookieExpireTime()
})
}
function saveCookies() {
chrome.cookies.getAll({ domain: '.e-hentai.org' }, function (cookies) {
cookies.forEach(cookie => {
if (['ipb_', 'uconfig'].some(v => cookie.name.includes(v))) {
chrome.cookies.set({
url: 'https://exhentai.org/',
name: cookie.name,
value: cookie.value,
domain: '.exhentai.org',
path: '/',
expirationDate: cookieExpireTime()
})
}
})

return true
} catch (e) {
return false
}
})
}

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request == 'reload') {
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.reload(tab.id)
})
} else if (request == 'cookieDataSet') {
sendResponse((setHentaiCookies() ? 'ok' : 'Unable to set cookies'))
} else if (request == 'deleteAllCookies') {
let urlEx = 'https://exhentai.org/'
let urlEh = 'http://e-hentai.org/'
chrome.cookies.remove({ name: 'yay', url: urlEx }, function () { })
chrome.cookies.remove({ name: 'ipb_anonlogin', url: urlEx }, function () { })
chrome.cookies.remove({ name: 'ipb_member_id', url: urlEx }, function () { })
chrome.cookies.remove({ name: 'ipb_pass_hash', url: urlEx }, function () { })
chrome.cookies.remove({ name: 'ipb_session_id', url: urlEx }, function () { })
chrome.cookies.remove({ name: 'ipb_anonlogin', url: urlEh }, function () { })
chrome.cookies.remove({ name: 'ipb_member_id', url: urlEh }, function () { })
chrome.cookies.remove({ name: 'ipb_pass_hash', url: urlEh }, function () { })
chrome.cookies.remove({ name: 'ipb_session_id', url: urlEh }, function () { })
sendResponse()
} else {
console.log(request)
}
})
function deleteCookies() {
//
const ex = 'https://exhentai.org/'
const eh = 'http://e-hentai.org/'
//
chrome.cookies.remove({ url: ex, name: 'yay' })
chrome.cookies.remove({ url: ex, name: 'ipb_anonlogin' })
chrome.cookies.remove({ url: ex, name: 'ipb_member_id' })
chrome.cookies.remove({ url: ex, name: 'ipb_pass_hash' })
chrome.cookies.remove({ url: ex, name: 'ipb_session_id' })
//
chrome.cookies.remove({ url: eh, name: 'ipb_anonlogin' })
chrome.cookies.remove({ url: eh, name: 'ipb_member_id' })
chrome.cookies.remove({ url: eh, name: 'ipb_pass_hash' })
chrome.cookies.remove({ url: eh, name: 'ipb_session_id' })
}

0 comments on commit 2352132

Please sign in to comment.