Skip to content

Commit 13fc179

Browse files
authored
Merge pull request #66 from amarcu5/develop-1.0.0
v1.0.1
2 parents 73299ed + d65f9be commit 13fc179

15 files changed

+307
-52
lines changed

README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Install from the [Chrome Web Store](https://chrome.google.com/webstore/detail/pi
6464
* [Netflix](http://www.netflix.com)
6565
* [OCS](http://www.ocs.fr)
6666
* [Openload](http://www.openload.co)
67+
* [PBS](http://www.pbs.org)
6768
* [Periscope](http://www.periscope.tv)
6869
* [Plex](http://www.plex.tv)
6970
* [Seznam Zprávy](http://www.seznam.cz/zpravy)
@@ -111,10 +112,7 @@ The following build tools are used to build the extension:
111112

112113
These can be installed by executing the following command:
113114
```Shell
114-
npm install -g csso-cli
115-
npm install -g svgo
116-
npm install -g xar-js
117-
npm install -g google-closure-compiler
115+
npm install -g csso-cli svgo xar-js google-closure-compiler
118116
```
119117

120118
#### Steps
@@ -182,4 +180,4 @@ export const resource = {
182180
For more examples, please see the [source](https://github.com/amarcu5/PiPer/tree/master/src/)
183181

184182
## Acknowledgements
185-
* [Pied PíPer](https://github.com/JoeKuhns/PiedPiPer.safariextension) for the original inspiration and the Netflix icon
183+
* [Pied PíPer](https://github.com/JoeKuhns/PiedPiPer.safariextension) for the original inspiration

make.sh

+18-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
EXTENSION_NAME="PiPer"
66

7-
SOURCE_FILES=("main.js" "fix.js" "background.js" "install.js" "localization-bridge.js")
7+
SOURCE_FILES=("main.js" "fix.js" "background.js" "install.js" "localization-bridge.js" "legacy.js")
88

99
# Certifcate paths
1010
LEAF_CERT_PATH="../certs/cert.pem"
@@ -226,24 +226,6 @@ if [[ "${compress_svg}" -eq 1 ]]; then
226226
${SVGO_PATH} -q -f "out/${EXTENSION_NAME}/images"
227227
fi
228228

229-
# Compress all inline CSS with CSSO
230-
if [[ "${compress_css}" -eq 1 ]]; then
231-
function minify_css() {
232-
echo "$@" | sed -e 's/\\"/"/g' -e 's/\\\$/$/g' | ${CSSO_PATH} --declaration-list
233-
}
234-
export -f minify_css
235-
export CSSO_PATH
236-
for path in "out/${EXTENSION_NAME}/scripts"/{*,**/*}.js; do
237-
[[ ! -f "${path}" ]] && continue
238-
source=$(cat "${path}")
239-
echo "echo \"$(sed -e 's/\\/\\\\/g' -e 's/\$/\\$/g' -e 's/`/\\`/g' -e 's/\"/\\\"/g' -e 's/\\n/\\\\n/g' <<< "$source" \
240-
| tr '\n' '\f' \
241-
| sed -E 's/\/\*\*[[:space:]]+CSS[[:space:]]+\*\/[[:space:]]*\([[:space:]]*\\`([^`]*)\\`[[:space:]]*\)/\\`\$(minify_css '\''\1'\'')\\`/g' \
242-
| tr '\f' '\n')\"" \
243-
| sh > "${path}"
244-
done
245-
fi
246-
247229
# Get current version from git if automatic versioning enabled
248230
if [[ "${update_version}" -eq 1 ]]; then
249231

@@ -344,6 +326,23 @@ for target in "${targets[@]}"; do
344326
# Copy target specific items to target output folder
345327
cp -r "src/${target}"/* "out/${EXTENSION_NAME}-${target}${target_extension}/" 2>/dev/null
346328

329+
# Compress all inline CSS with CSSO
330+
if [[ "${compress_css}" -eq 1 ]]; then
331+
function minify_css() {
332+
echo "$@" | sed -e 's/\\"/"/g' -e 's/\\\$/$/g' | ${CSSO_PATH} --declaration-list
333+
}
334+
export -f minify_css
335+
export CSSO_PATH
336+
for path in "out/${EXTENSION_NAME}-${target}${target_extension}${common_file_path}/scripts"/{*,**/*}.js; do
337+
[[ ! -f "${path}" ]] && continue
338+
source=$(cat "${path}")
339+
echo "echo \"$(sed -e 's/\\/\\\\/g' -e 's/\$/\\$/g' -e 's/`/\\`/g' -e 's/\"/\\\"/g' -e 's/\\n/\\\\n/g' <<< "$source" \
340+
| tr '\n' '\f' \
341+
| sed -E 's/\/\*\*[[:space:]]+CSS[[:space:]]+\*\/[[:space:]]*\([[:space:]]*\\`([^`]*)\\`[[:space:]]*\)/\\`\$(minify_css '\''\1'\'')\\`/g' \
342+
| tr '\f' '\n')\"" \
343+
| sh > "${path}"
344+
done
345+
fi
347346

348347
# Use closure compiler to compress javascript
349348
function remove_element() {

out/PiPer-chrome.zip

80 Bytes
Binary file not shown.

out/PiPer-safari-legacy.safariextz

919 Bytes
Binary file not shown.

out/PiPer-safari.pkg

0 Bytes
Binary file not shown.

src/common/scripts/captions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ const prepareCaptions = function(video) {
7676
// Otherwise create new caption track
7777
info('Caption track created');
7878
track = video.addTextTrack('captions', TRACK_ID, 'en');
79-
track.mode = 'showing';
8079
};
8180

8281
/**
@@ -124,6 +123,7 @@ const removeCaptions = function(video, workaround = true) {
124123
const addCaption = function(video, caption) {
125124

126125
info(`Showing caption '${caption}'`);
126+
track.mode = 'showing';
127127
track.addCue(new VTTCue(video.currentTime, video.currentTime + 60, caption));
128128

129129
if (getBrowser() == Browser.SAFARI) {

src/common/scripts/externs.js

+40-10
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,7 @@ HTMLVideoElement.prototype.webkitSetPresentationMode = function(mode) {};
2424
/** @type {string} */
2525
TextTrack.prototype.label;
2626

27-
/** @return {undefined} */
28-
safari.extension.dispatchMessage = function(message, userInfo) {};
29-
30-
/** @const */
31-
safari.self = {};
32-
33-
/** @return {undefined} */
34-
safari.self.addEventListener = function(type, listener) {};
35-
36-
/** @constructor */
27+
/** @interface */
3728
const SafariExtensionMessageEvent = function() {};
3829

3930
/** @type {*} */
@@ -42,6 +33,24 @@ SafariExtensionMessageEvent.prototype.message;
4233
/** @type {string} */
4334
SafariExtensionMessageEvent.prototype.name;
4435

36+
/** @type {EventTarget} */
37+
SafariExtensionMessageEvent.prototype.target;
38+
39+
/** @interface */
40+
const SafariEventTarget = function() {};
41+
42+
/** @return {function(string,function(SafariExtensionMessageEvent),boolean=):undefined} */
43+
SafariEventTarget.prototype.addEventListener = function(type, listener, capture) {};
44+
45+
/** @return {function(string,function(SafariExtensionMessageEvent),boolean=):undefined} */
46+
SafariEventTarget.prototype.removeEventListener = function(type, listener, capture) {};
47+
48+
/** @type {!SafariEventTarget} */
49+
safari.self;
50+
51+
/** @type {function(string,*=):undefined} */
52+
safari.extension.dispatchMessage = function(message, userInfo) {};
53+
4554

4655
/* Legacy Safari Extension */
4756

@@ -51,6 +60,27 @@ safari.extension.settings = {};
5160
/** @return {undefined} */
5261
safari.extension.settings.clear = function() {};
5362

63+
/** @type {!SafariEventTarget} */
64+
safari.application;
65+
66+
/** @const */
67+
safari.self.tab = {};
68+
69+
/** @type {function(string,*=):undefined} */
70+
safari.self.tab.dispatchMessage = function(message, userInfo) {};
71+
72+
/** @interface */
73+
const SafariBrowserTab = function() {};
74+
75+
/** @type {SafariWebPageProxy} */
76+
SafariBrowserTab.prototype.page;
77+
78+
/** @interface */
79+
const SafariWebPageProxy = function() {};
80+
81+
/** @type {function(string,*=):undefined} */
82+
SafariWebPageProxy.prototype.dispatchMessage = function(message, userInfo) {};
83+
5484

5585
/* Chrome Extension */
5686

src/common/scripts/resources/hulu.js

+35-15
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,51 @@
1-
import { getResource } from './../common.js'
1+
import { getButton } from './../button.js'
22

33
export const domain = 'hulu';
44

55
export const resource = {
6-
buttonClassName: 'simple-button',
76
buttonDidAppear: function() {
8-
const buttonParent = getResource().buttonParent();
9-
buttonParent.querySelector('.progress-bar-tracker').style.width = 'calc(100% - 380px)';
10-
buttonParent.querySelector('.progress-time-container').style.marginRight = '45px';
7+
8+
// Get localized button title and hide default tooltip
9+
const button = getButton();
10+
const /** string */ title = button.title;
11+
button.title = '';
12+
13+
// Create stylized tooltip and add to DOM
14+
const tooltip = /** @type {HTMLElement} */ (document.createElement('div'));
15+
tooltip.className = 'button-tool-tips';
16+
tooltip.style.cssText = /** CSS */ (`
17+
white-space: nowrap;
18+
padding: 0 5px;
19+
right: 0;
20+
`);
21+
tooltip.textContent = title.toUpperCase();
22+
button.appendChild(tooltip);
23+
24+
// Display stylized tooltip on mouseover
25+
button.addEventListener('mouseover', function() {
26+
tooltip.style.display = 'block';
27+
});
28+
button.addEventListener('mouseout', function() {
29+
tooltip.style.display = 'none';
30+
});
1131
},
1232
buttonElementType: 'div',
13-
buttonHoverStyle: /** CSS */ (`
14-
filter: brightness(50%) sepia(1) hue-rotate(58deg) saturate(160%) brightness(110%) !important;
15-
`),
33+
buttonHoverStyle: /** CSS */ (`opacity: 1.0 !important`),
34+
buttonInsertBefore: function(/** Element */ parent) {
35+
return document.querySelector('.controls__view-mode-button');
36+
},
1637
buttonParent: function() {
17-
return document.querySelector('#site-player .main-bar');
38+
return document.querySelector('#dash-player-container .controls__menus-right');
1839
},
19-
buttonScale: 0.7,
2040
buttonStyle: /** CSS */ (`
21-
top: -45px;
22-
left: -50px;
23-
filter: brightness(80%);
41+
opacity: 0.7;
42+
cursor: pointer;
43+
width: 24px;
2444
`),
2545
captionElement: function() {
26-
return document.querySelector('.closed-caption-container');
46+
return document.querySelector('.closed-caption-outband');
2747
},
2848
videoElement: function() {
29-
return document.getElementById('content-video-player');
49+
return document.querySelector('.video-player');
3050
},
3151
};

src/common/scripts/resources/pbs.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { getResource } from './../common.js'
2+
import { videoPlayingPictureInPicture, togglePictureInPicture } from './../video.js'
3+
4+
export const domain = 'pbs';
5+
6+
export const resource = {
7+
buttonClassName: 'jw-icon jw-icon-inline jw-button-color jw-reset',
8+
buttonDidAppear: function() {
9+
const fullscreenButton = document.querySelector('.jw-icon-fullscreen');
10+
fullscreenButton.addEventListener('click', function() {
11+
const video = /** @type {?HTMLVideoElement} */ (getResource().videoElement());
12+
if (videoPlayingPictureInPicture(video)) togglePictureInPicture(video);
13+
});
14+
},
15+
buttonElementType: 'div',
16+
buttonHoverStyle: /** CSS */ (`opacity: 1 !important`),
17+
buttonInsertBefore: function(/** Element */ parent) {
18+
return parent.lastChild;
19+
},
20+
buttonParent: function() {
21+
return document.querySelector('.jw-button-container');
22+
},
23+
buttonScale: 0.6,
24+
buttonStyle: /** CSS */ (`opacity: 0.8`),
25+
videoElement: function() {
26+
return document.querySelector('.jw-video');
27+
},
28+
};

src/common/scripts/resources/plex.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ export const resource = {
1414
const e = document.querySelector('div[class^="FullPlayerTopControls-topControls"]');
1515
return /** @type {?Element} */ (e && e.lastChild);
1616
},
17-
buttonScale: 0.6,
17+
buttonScale: 2,
1818
buttonStyle: /** CSS */ (`
1919
position: relative;
2020
top: -3px;
21+
width: 30px;
2122
padding: 10px;
2223
border: 0px;
2324
background: transparent;
2425
opacity: 0.7;
26+
outline: 0;
2527
text-shadow: 0px 0px 4px rgba(0, 0, 0, 0.45);
2628
`),
2729
captionElement: function() {

src/safari-legacy/Info.plist

+6
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@
1616
<string>0.0</string>
1717
<key>CFBundleVersion</key>
1818
<string>0</string>
19+
<key>Chrome</key>
20+
<dict>
21+
<key>Global Page</key>
22+
<string>global.html</string>
23+
</dict>
1924
<key>Content</key>
2025
<dict>
2126
<key>Scripts</key>
2227
<dict>
2328
<key>End</key>
2429
<array>
2530
<string>scripts/main.js</string>
31+
<string>scripts/legacy.js</string>
2632
</array>
2733
</dict>
2834
</dict>

src/safari-legacy/global.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>PiPer</title>
5+
<script src="scripts/background.js"></script>
6+
</head>
7+
<body>
8+
</body>
9+
</html>
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const messageHandler = function(/** SafariExtensionMessageEvent */ messageEvent) {
2+
switch (messageEvent.name) {
3+
case 'getUpgradeAlertShown':
4+
const setting = /** @type {string|undefined} */ (safari.extension.settings['upgradeAlertShown']);
5+
const target = /** @type {SafariBrowserTab} */ (messageEvent.target);
6+
target.page.dispatchMessage('upgradeAlertShownResponse', parseInt(setting || '0', 10));
7+
break;
8+
case 'setUpgradeAlertShown':
9+
safari.extension.settings['upgradeAlertShown'] = messageEvent.message;
10+
break;
11+
}
12+
}
13+
safari.application.addEventListener('message', messageHandler, false);

0 commit comments

Comments
 (0)