Skip to content

Instantly share code, notes, and snippets.

View Gandum2077's full-sized avatar
😘
Hello!

Gandum2077

😘
Hello!
View GitHub Profile
@Gandum2077
Gandum2077 / player.js
Last active January 27, 2020 01:54
改动使其支持播放本地和远程视频 JSBox video player based on AVPlayerViewController
const frameworks = ["AVFoundation", "AVKit"];
frameworks.forEach(name => {
$objc("NSBundle").$bundleWithPath(`/System/Library/Frameworks/${name}.framework`).$load();
});
const gravities = {
resize: "AVLayerVideoGravityResize",
resizeAspect: "AVLayerVideoGravityResizeAspect",
resizeAspectFill: "AVLayerVideoGravityResizeAspectFill",
}
@Gandum2077
Gandum2077 / shared-session.js
Created January 8, 2020 02:21
Download files with shared session
function download(params) {
params = params || {};
params.handlers = params.handlers || {};
const url = params.url;
const method = params.method || "GET";
const timeout = params.timeout || 60;
const header = params.header || {};
const body = params.body;
const callback = params.handler;
@Gandum2077
Gandum2077 / objc-downloader.js
Created January 8, 2020 02:15
Download file in JSBox using Objective-C APIs
$define({
type: "DownloadEventHandler: NSObject<NSURLSessionDownloadDelegate>",
props: ["handlers"],
events: {
"URLSession:downloadTask:didFinishDownloadingToURL:": (session, task, location) => {
const data = $objc("NSData").$dataWithContentsOfURL(location).$copy();
const filename = task.$response().$suggestedFilename();
const result = {
"url": task.$originalRequest().$URL().$absoluteString().jsValue(),
"data": data.jsValue(),
@Gandum2077
Gandum2077 / SDWebImageManager.js
Created January 8, 2020 02:15
Using SDWebImageManager in JSBox
const manager = $objc("SDWebImageManager").$sharedManager();
const url = $objc("NSURL").$URLWithString("");
const options = 0;
const modifier = $objc("SDWebImageDownloaderRequestModifier").$requestModifierWithBlock($block("NSURLRequest *, NSURLRequest *", request => {
const mutableRequest = request.$mutableCopy();
mutableRequest.$setValue_forHTTPHeaderField("value", "key");
return mutableRequest.$copy();
}));
@Gandum2077
Gandum2077 / login-dialog.js
Created December 25, 2019 05:51
Create log-in dialog using Objective-C APIs in JSBox
//---- Definition ----/
const UIAlertActionStyle = {
Default: 0,
Cancel: 1,
Destructive: 2,
}
const UIAlertControllerStyle = {
ActionSheet: 0,