Basic Safari extension
13
Open in Yattee/Info.plist
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionPointIdentifier</key>
|
||||
<string>com.apple.Safari.web-extension</string>
|
||||
<key>NSExtensionPrincipalClass</key>
|
||||
<string>$(PRODUCT_MODULE_NAME).SafariWebExtensionHandler</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
10
Open in Yattee/Open in Yattee.entitlements
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.app-sandbox</key>
|
||||
<true/>
|
||||
<key>com.apple.security.files.user-selected.read-only</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
BIN
Open in Yattee/Resources/images/icon-128.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
Open in Yattee/Resources/images/icon-256.png
Normal file
After Width: | Height: | Size: 42 KiB |
BIN
Open in Yattee/Resources/images/icon-48.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
Open in Yattee/Resources/images/icon-512.png
Normal file
After Width: | Height: | Size: 128 KiB |
BIN
Open in Yattee/Resources/images/icon-64.png
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
Open in Yattee/Resources/images/icon-96.png
Normal file
After Width: | Height: | Size: 9.5 KiB |
BIN
Open in Yattee/Resources/images/toolbar-icon-16.png
Normal file
After Width: | Height: | Size: 454 B |
BIN
Open in Yattee/Resources/images/toolbar-icon-19.png
Normal file
After Width: | Height: | Size: 569 B |
BIN
Open in Yattee/Resources/images/toolbar-icon-32.png
Normal file
After Width: | Height: | Size: 919 B |
BIN
Open in Yattee/Resources/images/toolbar-icon-38.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
36
Open in Yattee/Resources/manifest.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"default_locale": "en",
|
||||
|
||||
"name": "Open in Yattee",
|
||||
"description": "Open YouTube videos in Yattee app",
|
||||
"version": "1.0",
|
||||
|
||||
"icons": {
|
||||
"48": "images/icon-48.png",
|
||||
"96": "images/icon-96.png",
|
||||
"128": "images/icon-128.png",
|
||||
"256": "images/icon-256.png",
|
||||
"512": "images/icon-512.png"
|
||||
},
|
||||
"content_scripts": [{
|
||||
"js": [ "content.js" ],
|
||||
"matches": [
|
||||
"*://*.youtube-nocookie.com/*",
|
||||
"*://*.youtube.com/*",
|
||||
"*://*.youtu.be/*"
|
||||
]
|
||||
}],
|
||||
|
||||
"browser_action": {
|
||||
"default_popup": "popup.html",
|
||||
"default_icon": {
|
||||
"16": "images/toolbar-icon-16.png",
|
||||
"19": "images/toolbar-icon-19.png",
|
||||
"32": "images/toolbar-icon-32.png",
|
||||
"38": "images/toolbar-icon-38.png"
|
||||
}
|
||||
},
|
||||
|
||||
"permissions": [ ]
|
||||
}
|
15
Open in Yattee/Resources/popup.css
Normal file
@@ -0,0 +1,15 @@
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
}
|
||||
|
||||
body {
|
||||
width: 100px;
|
||||
padding: 10px;
|
||||
|
||||
font-family: system-ui;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
/* Dark Mode styles go here. */
|
||||
}
|
11
Open in Yattee/Resources/popup.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="popup.css">
|
||||
<script type="module" src="popup.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<strong>Hello World!</strong>
|
||||
</body>
|
||||
</html>
|
1
Open in Yattee/Resources/popup.js
Normal file
@@ -0,0 +1 @@
|
||||
console.log("Hello World!", browser);
|
15
Open in Yattee/SafariWebExtensionHandler.swift
Normal file
@@ -0,0 +1,15 @@
|
||||
import os.log
|
||||
import SafariServices
|
||||
|
||||
final class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
|
||||
func beginRequest(with context: NSExtensionContext) {
|
||||
let item = context.inputItems[0] as! NSExtensionItem
|
||||
let message = item.userInfo?[SFExtensionMessageKey]
|
||||
os_log(.default, "Received message from browser.runtime.sendNativeMessage: %@", message as! CVarArg)
|
||||
|
||||
let response = NSExtensionItem()
|
||||
response.userInfo = [SFExtensionMessageKey: ["Response to": message]]
|
||||
|
||||
context.completeRequest(returningItems: [response], completionHandler: nil)
|
||||
}
|
||||
}
|
26
Open in Yattee/content.js
Normal file
@@ -0,0 +1,26 @@
|
||||
if (document.readyState !== 'complete') {
|
||||
window.addEventListener('load', redirectAndReplaceContentWithLink);
|
||||
} else {
|
||||
redirectAndReplaceContentWithLink();
|
||||
}
|
||||
|
||||
function yatteeUrl() {
|
||||
return window.location.href.replace(/^https?:\/\//, 'yattee://');
|
||||
}
|
||||
|
||||
function yatteeLink() {
|
||||
return '<a href="'+ yatteeUrl() +'" onclick=\'window.location.href="'+ yatteeUrl() +'"\'>Open in Yattee</a>';
|
||||
}
|
||||
|
||||
function redirect() {
|
||||
window.location.href = yatteeUrl()
|
||||
}
|
||||
|
||||
function replaceContentWithLink() {
|
||||
document.querySelector('body').innerHTML = yatteeLink();
|
||||
}
|
||||
|
||||
function redirectAndReplaceContentWithLink(){
|
||||
redirect()
|
||||
replaceContentWithLink()
|
||||
}
|