Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/Develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerardufoin committed May 9, 2017
2 parents fcb5d1e + fd604b4 commit 0896a2e
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 74 deletions.
20 changes: 4 additions & 16 deletions Scripts/Bookmarks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

function Bookmarks() {
function BookmarksPage() {

// The data of the images is processed by JQuery Tooltip and removed. So we need to get them before it happens using mutations.
var observer = new MutationObserver(function(mutations) {
Expand All @@ -19,7 +19,8 @@ function Bookmarks() {
characterData: false,
subtree: true,
attributeFilter: [ "title" ]
});
}
);

$(document).ready(function () {

Expand All @@ -46,9 +47,6 @@ function Bookmarks() {
$(this).html($(this).find("img"));
});

// Bookmarks infos
var mangas = {};

// Loop through all bookmarks
$(".fk-bookmarkRow").each(function() {

Expand All @@ -60,18 +58,8 @@ function Bookmarks() {
}
}

// Kissmanga, why do you use bookmark ID instead of the manga ID to manage bookmark ? :'(
var m = {
// href will be used to do fancy stuffs on the front page, like a blacklist (as the mid/bid are not on the front page)
href: $(this).find("td:eq(0) a.aManga").attr("href").substring(1),
bid: $(this).find("td:eq(2) a").attr("bdid")
};
mangas[$(this).find("td:eq(3) a").attr("mid")] = m;
});

// Storage of the bookmarks in memory. Used to add bookmark management directly on the mangas' chapters
chrome.storage.local.set({"fk-bookmarks": mangas});
});
}

Options.init(Bookmarks);
Options.init(BookmarksPage);
1 change: 1 addition & 0 deletions Scripts/Chapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";

// Variable used to get images height/width. Created here to avoid spamming "new"
var fk_test_image = new Image();

function Chapter() {
Expand Down
69 changes: 69 additions & 0 deletions Scripts/Class/Bookmarks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Bookmarks class (do not confuse with Bookmarks pages script). Allow to get user's bookmarks using the sync function
// During the sync, functions can be registered to be called at the end of the synchronization
var Bookmarks = {
mangas: {},
syncCallbacks: [],
syncing: false,
// Get the bookmarks from a jquery element passed in parameter
setBookmarks: function(bookmarks) {
this.mangas = {};
var obj = this;
bookmarks.each(function() {
var m = {
// href will be used to do fancy stuffs on the front page, like a blacklist (as the mid/bid are not on the front page)
href: $(this).find("td:eq(0) a.aManga").attr("href").substring(1),
bid: $(this).find("td:eq(2) a").attr("bdid"),
read: ($(this).find("td:eq(2) .aRead").css('display') != 'none')
};
obj.mangas[$(this).find("td:eq(3) a").attr("mid")] = m;
});
},
// Synchronize the bookmarks.
sync: function(callback = null) {
if (callback != null) {
this.syncCallbacks.push(callback);
}
this.syncing = true;
var obj = this;
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://kissmanga.com/BookmarkList", true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
obj.setBookmarks($(xhr.responseText).find(".listing tr:not(:first-child)"));
obj.executeCallbacks();
obj.syncing = false;
}
}
xhr.send();
},
// Queue a function for when the bookmarks are loaded
queueCallback: function(callback) {
if (this.syncing) {
this.syncCallbacks.push(callback);
} else {
callback();
}
},
// Execute all the stored synchronization dependant callbacks
executeCallbacks: function() {
for (var i = 0; i < this.syncCallbacks.length; ++i) {
this.syncCallbacks[i]();
}
this.syncCallbacks = [];
},
// Get a bookmark using its url (when no mID is available (looking at you, frontpage è.é))
getByUrl: function(url) {
for (var key in this.mangas) {
if (this.mangas.hasOwnProperty(key) && this.mangas[key].href == url) {
var ret = this.mangas[key];
ret.mid = key;
return ret;
}
}
return null;
},
// Check if there is any bookmarks loaded
isEmpty: function() {
return (Object.keys(this.mangas).length == 0);
}
};
1 change: 1 addition & 0 deletions Scripts/Class/Options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Option class. Allow to manipulate FreeKiss options
// Every script should put its main function in init to check if FreeKiss is disabled
var Options = {
// Default options
options: {
maxPageWidth: 800,
maxDoublePageWidth: 1800,
Expand Down
Loading

0 comments on commit 0896a2e

Please sign in to comment.