-
Notifications
You must be signed in to change notification settings - Fork 39
Adds @grant to model for userscripts #317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// https://wiki.greasespot.net/GM.getValue | ||
GM.getValue = function(key, defaultValue) { | ||
return Promise.resolve(localStorage.getItem(key) ?? defaultValue); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// https://wiki.greasespot.net/GM.setValue | ||
GM.setValue = function(key, value) { | ||
TravisTheTechie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
localStorage.setItem(key, value) | ||
return Promise.resolve(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
let GM_getValue = function(key, defaultValue) { | ||
return localStorage.getItem(key) ?? defaultValue; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
let GM_setValue = function(key, value) { | ||
localStorage.setItem(key, value); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// > All scripts always get GM.info even without specifically requesting it. | ||
// per https://wiki.greasespot.net/@grant | ||
let GM = { | ||
info: { | ||
// https://wiki.greasespot.net/GM.info | ||
scriptHandler: 'TornPDA', | ||
scriptMetaStr: '', | ||
scriptWillUpdate: false, | ||
version: '0.0.0', | ||
script: { | ||
name: 'Default Script', | ||
namespace: 'default', | ||
description: 'A default userscript.', | ||
excludes: [], | ||
includes: [], | ||
matches: [], | ||
resources: {}, | ||
'run-at': "document-start", | ||
version: '0.0.0' | ||
} | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'dart:async' show Future; | ||
import 'dart:convert'; | ||
import 'package:flutter/services.dart' show rootBundle; | ||
|
||
class UserscriptApisProvider { | ||
static Map<String, String> _apis = {}; | ||
|
||
/// Initializes the provider by loading the API scripts from the assets. | ||
/// Returns a [Future] if someone wants to check for errors. | ||
static Future<Map<String, String>> initialize() async { | ||
_apis = await _getApisMap(_getApis()); | ||
return _apis; | ||
} | ||
|
||
static Map<String, String> get apis { | ||
return _apis; | ||
} | ||
|
||
static Future<Map<String, String>> _getApisMap( | ||
Future<List<String>> apiEntries) async { | ||
return apiEntries.then((fileList) async { | ||
return { | ||
for (var file in fileList) | ||
_mapFileNameToApiName(file): await rootBundle.loadString(file) | ||
}; | ||
}); | ||
} | ||
|
||
static String _mapFileNameToApiName(String fileName) { | ||
return fileName | ||
.replaceFirst('assets/userscripts/apis/', '') | ||
.replaceFirst('.js', ''); | ||
} | ||
|
||
static Future<List<String>> _getApis() async { | ||
final manifestContent = await rootBundle.loadString('AssetManifest.json'); | ||
|
||
final Map<String, dynamic> manifestMap = json.decode(manifestContent); | ||
|
||
return manifestMap.keys | ||
.where((String key) => key.startsWith('assets/userscripts/apis/')) | ||
.where((String key) => key.endsWith('.js')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly a stupid question - why not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eh, just my habit of breaking things up like this. I like to think about it this way, though I guess technically it is less efficient (depending on the implementation) because you need to iterate twice. Happy to change it. |
||
.toList(); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.