-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #291 from Darock-Studio/feature/safariext
feat: Add Safari Extension
- Loading branch information
Showing
25 changed files
with
359 additions
and
13 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extension_name": { | ||
"message": "喵哩喵哩", | ||
"description": "喵哩喵哩 Safari 扩展" | ||
}, | ||
"extension_description": { | ||
"message": "This is SafariExtension. You should tell us what your extension does here.", | ||
"description": "Description of what the extension does." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
console.log("%cMeowBili Extension Here!", "color: #66CCFF;"); | ||
console.log("Current Link:", window.location.href); | ||
var bvidSpdArr = window.location.href.split('/'); | ||
var bvid = bvidSpdArr[bvidSpdArr.length - 1]; | ||
window.location.href = "drkbili://openbvid/" + bvid; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"manifest_version": 3, | ||
"default_locale": "en", | ||
|
||
"name": "__MSG_extension_name__", | ||
"description": "__MSG_extension_description__", | ||
"version": "1.0.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" | ||
}, | ||
|
||
"background": { | ||
"service_worker": "background.js" | ||
}, | ||
|
||
"content_scripts": [{ | ||
"js": [ "content.js" ], | ||
"matches": [ "*://*.bilibili.com/video/BV*" ] | ||
}], | ||
|
||
"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", | ||
"48": "images/toolbar-icon-48.png", | ||
"72": "images/toolbar-icon-72.png" | ||
} | ||
}, | ||
|
||
"permissions": [ ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
:root { | ||
color-scheme: light dark; | ||
} | ||
|
||
body { | ||
padding: 10px; | ||
|
||
font-family: system-ui; | ||
text-align: center; | ||
} | ||
|
||
@media (prefers-color-scheme: dark) { | ||
/* Dark Mode styles go here. */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>喵哩喵哩 Safari 扩展已生效</strong> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// | ||
// SafariWebExtensionHandler.swift | ||
// SafariExtension | ||
// | ||
// Created by memz233 on 2024/3/2. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the MeowBili open source project | ||
// | ||
// Copyright (c) 2024 Darock Studio and the MeowBili project authors | ||
// Licensed under GNU General Public License v3 | ||
// | ||
// See https://darock.top/LICENSE.txt for license information | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import SafariServices | ||
import os.log | ||
|
||
class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling { | ||
|
||
func beginRequest(with context: NSExtensionContext) { | ||
let request = context.inputItems.first as? NSExtensionItem | ||
|
||
let profile: UUID? | ||
if #available(iOS 17.0, macOS 14.0, *) { | ||
profile = request?.userInfo?[SFExtensionProfileKey] as? UUID | ||
} else { | ||
profile = request?.userInfo?["profile"] as? UUID | ||
} | ||
|
||
let message: Any? | ||
if #available(iOS 17.0, macOS 14.0, *) { | ||
message = request?.userInfo?[SFExtensionMessageKey] | ||
} else { | ||
message = request?.userInfo?["message"] | ||
} | ||
|
||
os_log(.default, "Received message from browser.runtime.sendNativeMessage: %@ (profile: %@)", String(describing: message), profile?.uuidString ?? "none") | ||
|
||
let response = NSExtensionItem() | ||
response.userInfo = [ SFExtensionMessageKey: [ "echo": message ] ] | ||
|
||
context.completeRequest(returningItems: [ response ], completionHandler: nil) | ||
} | ||
|
||
} |