Skip to content

Instantly share code, notes, and snippets.

@mrvivacious
mrvivacious / getIdOfAccessibilityNode.java
Created November 21, 2020 11:12
Get the ID of an AccessibilityNode for Android (read the note)
// For Android
// Get the ID of an Accessibility node
/*
* Get the associated nodeId of the passed in event source
* This works as long as AccessibilityNodes keep their IDs
* as the beginnings of their .toString() return values
*/
public String getId(AccessibilityNode node) {
@mrvivacious
mrvivacious / setTextInAccessibilityNode.java
Last active November 21, 2020 11:00
Paste text in an accessibility node on Android
// For Android
// Class must extend AccessibilityService to use this function verbatim
// Have fun
// Function will overwrite any existing text in the node
public void setText(AccessibilityNodeInfo node, String textToSet) {
Bundle arguments = new Bundle();
arguments.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE,
textToSet);
node.performAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SET_TEXT.getId(), arguments);
@mrvivacious
mrvivacious / getChromeURL.java
Last active April 6, 2023 06:18
Get the URL of the current page in the Google Chrome browser on Android
// For Android
// Get the URL of the current page in the Google Chrome browser
// Needs to be in a class that extends AccessibilityService
// A version of this code is used in PorNo!, a porn-blocker I wrote
// https://github.com/mrvivacious/PorNo-_Porn_Blocker/
//
// Have fun ~
String TAG = "Get Chrome URL: ";
@mrvivacious
mrvivacious / Age in days
Created November 4, 2020 09:37
Bash script for one's age in days
```sh
# https://stackoverflow.com/questions/4946785/
# https://stackoverflow.com/questions/1401482/
function age() {
dob="1900-31-01" # yyyy-dd-mm
today=$(date '+%Y-%d-%m')
echo Day $(((`date -jf %Y-%d-%m $today +%s` - `date -jf %Y-%d-%m $dob +%s`)/86400))
}
```