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

GET parameter support #144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ http://redditp.com
* Arrow keys, pgup/pgdown, spacebar change slides
* Swipe gestures on phones

## GET parameter

* time - time used for auto-next
* nsfw - en/disable nsfw content
* auto - en/disable auto-next
* sound - en/disable sound
* menu - hide the menu
* title - hide the title

## Features

* All /r/ subreddits, including different ?sort stuff.
Expand Down
70 changes: 70 additions & 0 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,38 @@ $(function () {
return Cookies.get(c_name);
};

var getGET = function (request) {
var $_GET=[];
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(a,name,value){$_GET[name]=value;});

if (request === 'time') {
if ($_GET['time'] !== 'undefined') {
return $_GET['time'];
}
} else if (request === 'nsfw') {
if ($_GET['nsfw'] !== 'undefined') {
return $_GET['nsfw'];
}
} else if (request === 'auto') {
if ($_GET['auto'] !== 'undefined') {
return $_GET['auto'];
}
} else if (request === 'sound') {
if ($_GET['sound'] !== 'undefined') {
return $_GET['sound'];
}
} else if (request === 'menu') {
if ($_GET['menu'] !== 'undefined') {
return $_GET['menu'];
}
} else if (request === 'title') {
if ($_GET['title'] !== 'undefined') {
return $_GET['title'];
}
}
return undefined;
};

var updateSound = function () {
rp.settings.sound = $('#sound').is(':checked');
setCookie(cookieNames.soundCookie, rp.settings.sound);
Expand Down Expand Up @@ -285,13 +317,29 @@ $(function () {
};

var initState = function () {
var collapseMenuByGET = getGET('menu');
if (collapseMenuByGET !== undefined) {
$('#controlsDiv .collapser').click();
}
var collapseTitleByGET = getGET('title');
if (collapseTitleByGET !== undefined) {
$('#titleDiv .collapser').click();
}

var nsfwByCookie = getCookie(cookieNames.nsfwCookie);
if (nsfwByCookie === undefined) {
rp.settings.nsfw = true;
} else {
rp.settings.nsfw = (nsfwByCookie === "true");
$("#nsfw").prop("checked", rp.settings.nsfw);
}
var nsfwByGET = getGET('nsfw');
if (nsfwByGET === undefined) {
rp.settings.nsfw = true;
} else {
rp.settings.nsfw = (nsfwByGET === "true");
$("#nsfw").prop("checked", rp.settings.nsfw);
}
$('#nsfw').change(updateNsfw);

// Fix sound cookie
Expand All @@ -302,6 +350,13 @@ $(function () {
rp.settings.sound = (soundByCookie === "true");
$("#sound").prop("checked", rp.settings.sound);
}
var soundByGET = getGET('sound');
if (soundByGET === undefined) {
rp.settings.sound = false;
} else {
rp.settings.sound = (soundByGET === "true");
$("#sound").prop("checked", rp.settings.sound);
}
$('#sound').change(updateSound);

var autoByCookie = getCookie(cookieNames.shouldAutoNextSlideCookie);
Expand All @@ -311,6 +366,13 @@ $(function () {
rp.settings.shouldAutoNextSlide = (autoByCookie === "true");
$("#autoNextSlide").prop("checked", rp.settings.shouldAutoNextSlide);
}
var autoByGET = getGET('auto');
if (autoByGET === undefined) {
updateAutoNext();
} else {
rp.settings.shouldAutoNextSlide = (autoByGET === "true");
$("#autoNextSlide").prop("checked", rp.settings.shouldAutoNextSlide);
}
$('#autoNextSlide').change(updateAutoNext);

var updateTimeToNextSlide = function () {
Expand All @@ -326,6 +388,14 @@ $(function () {
rp.settings.timeToNextSlide = parseFloat(timeByCookie) * 1000;
$('#timeToNextSlide').val(timeByCookie);
}
var timeByGET = getGET('time');
if (timeByGET === undefined) {
updateTimeToNextSlide();
} else {
rp.settings.timeToNextSlide = parseFloat(timeByGET) * 1000;
$('#timeToNextSlide').val(timeByGET);
}


$('#fullScreenButton').click(toggleFullScreen);

Expand Down