| 1 |
import constants from "../../js/constants.js"; |
| 2 |
|
| 3 |
function initWelcomePage() { |
| 4 |
let already_set = false; |
| 5 |
|
| 6 |
$(window).scroll(function () { |
| 7 |
if (already_set) { |
| 8 |
return; |
| 9 |
} |
| 10 |
if ($(window).scrollTop() > 400) { |
| 11 |
already_set = true; |
| 12 |
chrome.runtime.sendMessage({ |
| 13 |
type: "updateSettings", |
| 14 |
data: { seenComic: true } |
| 15 |
}); |
| 16 |
} |
| 17 |
}); |
| 18 |
} |
| 19 |
|
| 20 |
function initPinNudge() { |
| 21 |
function renderNudge() { |
| 22 |
$("body").addClass('unpinned-chrome'); |
| 23 |
initAnimationToggle(); |
| 24 |
} |
| 25 |
|
| 26 |
// chrome.action is only available in MV3 and chrome.browserAction is only available in <= MV2 |
| 27 |
// chrome.browserAction.getUserSettings doesn't exist in MV2 Chrome but does in Firefox |
| 28 |
let is_chromium_mv3 = !!chrome.action; |
| 29 |
let is_chromium_mv2 = chrome.browserAction && !chrome.browserAction.getUserSettings; |
| 30 |
if (is_chromium_mv2) { |
| 31 |
renderNudge(); |
| 32 |
} else if (is_chromium_mv3) { |
| 33 |
// Don't render pinning section if PB is already pinned |
| 34 |
chrome.action.getUserSettings(userSettings => { |
| 35 |
if (!userSettings.isOnToolbar) { |
| 36 |
renderNudge(); |
| 37 |
} |
| 38 |
}); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
function initAnimationToggle() { |
| 43 |
function showAnimation() { |
| 44 |
$("#pinning-instructions-animation").show(); |
| 45 |
$("#pinning-instructions-reduced-motion").hide(); |
| 46 |
$("#toggle-animation-icon").text("\u23F8"); // Pause icon |
| 47 |
$("#toggle-animation-label").text(chrome.i18n.getMessage("intro_animation_button_stop")); |
| 48 |
} |
| 49 |
function hideAnimation() { |
| 50 |
$("#pinning-instructions-animation").hide(); |
| 51 |
$("#pinning-instructions-reduced-motion").show(); |
| 52 |
$("#toggle-animation-icon").text("\u25B6"); // Play icon |
| 53 |
$("#toggle-animation-label").text(chrome.i18n.getMessage("intro_animation_button_play")); |
| 54 |
} |
| 55 |
|
| 56 |
let prefers_reduced_motion = window.matchMedia("(prefers-reduced-motion: reduce)").matches; |
| 57 |
|
| 58 |
// Set initial animation state based on user's reduced motion setting |
| 59 |
if (prefers_reduced_motion) { |
| 60 |
hideAnimation(); |
| 61 |
} else { |
| 62 |
showAnimation(); |
| 63 |
} |
| 64 |
|
| 65 |
$("#toggle-animation-btn").on("click", function () { |
| 66 |
let animation_visible = $("#pinning-instructions-animation").is(":visible"); |
| 67 |
if (animation_visible) { |
| 68 |
hideAnimation(); |
| 69 |
} else { |
| 70 |
showAnimation(); |
| 71 |
} |
| 72 |
}); |
| 73 |
} |
| 74 |
|
| 75 |
$(function () { |
| 76 |
initWelcomePage(); |
| 77 |
|
| 78 |
// Don't show the pin nudge on Android devices, where it's not applicable |
| 79 |
if (chrome.runtime.getPlatformInfo) { |
| 80 |
chrome.runtime.getPlatformInfo((info) => { |
| 81 |
if (!info || info.os != "android") { |
| 82 |
initPinNudge(); |
| 83 |
} else if (info && info.os == "android") { |
| 84 |
// On Android, update the graphic showing how to open the popup |
| 85 |
if (constants.BROWSER == "firefox") { |
| 86 |
$('#toolbar-icon').attr("src", "images/android-firefox-popup-instructions.png"); |
| 87 |
} else if (constants.BROWSER == "edge") { |
| 88 |
$('#toolbar-icon').attr("src", "images/android-edge-popup-instructions.png"); |
| 89 |
} |
| 90 |
} |
| 91 |
}); |
| 92 |
} else { |
| 93 |
initPinNudge(); |
| 94 |
} |
| 95 |
}); |