Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sticky + Preloaded Themes #32

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
55 changes: 52 additions & 3 deletions manga-loader.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,51 @@ var createButton = function(text, action, styleStr) {
return button;
};

var preloadProfiles = function(cssProfiles) {
//new Defaults
var Profiles = [
{name: "Webtoons", css:
toStyleStr({
'background-color':'white !important'
}, 'body') + "\n" +
toStyleStr({
'color':'white',
'background-color':'rgba(0,0,0, .5)',
'border':'1px solid black'
}, '.ml-chap-nav a') + "\n" +
toStyleStr({
'color':'black',
'background-color':'rgba(255,255,255, 1)'
}, '.ml-chap-nav a:hover') + "\n" +
toStyleStr({
'position':'absolute',
'margin-left':'0px',
'border-radius':'0px 10px 10px 0px',
'background-color':'#444'
}, '.ml-counter') + "\n" +
toStyleStr({
'margin':'0px auto'
}, '.ml-images img')
}
];

//Load not already inserted defaults
var i, j, tmp, find;
for (i = 0; i < Profiles.length; i++) {
find = false;
for (j = 0; j < cssProfiles.length; j++) {
tmp = cssProfiles[j];
if(tmp.name == Profiles[i].name) {
find = true;
break;
}
}
if(!find) {
cssProfiles.push(Profiles[i]);
}
}
};

var getViewer = function(prevChapter, nextChapter) {
var viewerCss = toStyleStr({
'background-color': 'black !important',
Expand Down Expand Up @@ -1571,6 +1616,10 @@ var getViewer = function(prevChapter, nextChapter) {
'z-index': '100',
'position': 'relative'
}, '.ml-counter'),
navdivCss = toStyleStr({
'position': 'sticky',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how I feel about the sticky nav, it overlaps the image and kind of distracts a bit.

'top': '5px'
}, '.ml-chap-nav'),
navCss = toStyleStr({
'text-decoration': 'none',
'color': 'white',
Expand Down Expand Up @@ -1644,9 +1693,9 @@ var getViewer = function(prevChapter, nextChapter) {
'<i class="fa fa-cog ml-button ml-settings-button" title="Adjust userscript settings"></i> ' +
'<i class="fa fa-refresh ml-button ml-manual-reload" title="Manually refresh next clicked image."></i></span></div>';
// combine ui elements
document.body.innerHTML = nav + '<div class="ml-images"></div>' + nav + floatingMsg + stats;
document.body.innerHTML = nav + '<div class="ml-images"></div>' + floatingMsg + stats;
// add main styles
addStyle('main', true, viewerCss, imagesCss, imageCss, counterCss, navCss, navHoverCss, statsCss, statsCollapseCss, statsHoverCss, boxCss, floatingMsgCss, buttonCss, keySettingCss, autoloadSettingCss, floatingMsgAnchorCss);
addStyle('main', true, viewerCss, imagesCss, imageCss, counterCss, navdivCss, navCss, navHoverCss, statsCss, statsCollapseCss, statsHoverCss, boxCss, floatingMsgCss, buttonCss, keySettingCss, autoloadSettingCss, floatingMsgAnchorCss);
// add user styles
var userCss = storeGet('ml-setting-css-profiles');
var curProf = storeGet('ml-setting-css-current') || 'Default';
Expand Down Expand Up @@ -1810,6 +1859,7 @@ var getViewer = function(prevChapter, nextChapter) {
var settings = '<table><tr><td>';
// Custom CSS
var cssProfiles = storeGet('ml-setting-css-profiles');
preloadProfiles(cssProfiles);
Copy link
Owner

@fuzetsu fuzetsu Jun 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call needs to be after the following if that creates the default profile or it will crash on a fresh install (since cssProfiles will be undefined).

if(!cssProfiles || cssProfiles.length === 0) {
cssProfiles = [{name: 'Default', css: storeGet('ml-setting-css') || ''}];
storeSet('ml-setting-css-profiles', cssProfiles);
Expand Down Expand Up @@ -2241,7 +2291,6 @@ var MLoaderLoadImps = function(imps) {
return true;
}
});

if (!success) {
log('no implementation for ' + pageUrl, 'error');
}
Expand Down