Comments (3)
I have macros that will open 1st/2nd/3rd link when I am on Google for me.
For example I have bound this macro to ctrl+v:
And it will instantly open first result on Google for me.
I also use sVim and have bindings configured. Pressing d
will open link hints and I can choose results by typing letters:
from ama.
The macro calls this JXA:
(() => {
'use strict';
const main = () => {
const
linkIndex = 0,
strXPath = "//*[@class='r']/a",
saf = Application("Safari"),
ws = saf.windows;
return bindLR(
0 < ws.length ? (
Right(ws.at(0))
) : Left('No window open in Safari'),
w => {
const
xs = pageXPathHarvest(
saf, w, strXPath
);
return 0 < xs.length ? (
// Safari effect
//tabsOpened(saf, w, xs),
nthLinkOpened(saf, xs, linkIndex),
// Keyboard Maestro value
Right(
xs.reduce(
(a, link) =>
`${a}[${link[0]}](${link[1]})\n`,
''
)
)
) : Left(
'Perhaps not a Google search page ?\n' +
'(No links matching "' + strXPath + '")'
);
}
);
};
// SAFARI ---------------------------------------------
// Harvest elements from Safari by XPath pattern
const pageXPathHarvest = (browser, oWin, strXPath) =>
browser.doJavaScript(
`(${xpathHarvest})("${strXPath}")`, { in
: oWin.currentTab
}
);
// tabsOpened :: Application -> Window -> (String, String) -> IO()
const tabsOpened = (safari, oWin, links) => {
const winTabs = oWin.tabs;
links.map(link => winTabs.push(safari.Tab({
url: link[1]
})))
};
// nthLinkOpened :: Application -> (String, String) -> Int -> IO()
const nthLinkOpened = (safari, links, i) =>
(ds =>
(
ds.length < 1 && ds.push(safari.Document()),
ds.at(0)
)
.url = links[i][1]
)(safari.documents);
// Harvesting function to run in the browser context
const xpathHarvest = strPath => {
const
r = document.evaluate(strPath, document, null, 0, null),
xs = [];
let oNode;
while (oNode = r.iterateNext()) {
xs.push([oNode.text, oNode.href]);
}
return xs;
};
// GENERIC FUNCTIONS ----------------------------------
// https://github.com/RobTrew/prelude-jxa
// Left :: a -> Either a b
const Left = x => ({
type: 'Either',
Left: x
});
// Right :: b -> Either a b
const Right = x => ({
type: 'Either',
Right: x
});
// bindLR (>>=) :: Either a -> (a -> Either b) -> Either b
const bindLR = (m, mf) =>
m.Right !== undefined ? (
mf(m.Right)
) : m;
// MAIN
return main();
})();
I share all macros I use on Gumorad.
from ama.
Thank you :)
from ama.
Related Issues (20)
- What is your "time to automate" moment? HOT 3
- How do you organize todos across multiple apps? HOT 1
- what are your clever techniques to learn/research a completely new topic? HOT 2
- Remapping Ctrl and ESC HOT 1
- Routines, Habits, Lessons Learned HOT 1
- your wiki's impact on job finding HOT 2
- You know anything about using vimwiki and github pages with jekyll as a possible digital garden solution? HOT 8
- Why Go? HOT 2
- Why are you following 6.5k people on github? HOT 3
- What steps do your alfred workflow follows? (I don't have a mac nor a viewer and want to do something like it for Win) HOT 3
- Antibody zsh plugin manager is deprecated 😢 HOT 1
- Why do you use both Arq and Backblaze? HOT 6
- What pdf viewer do you use? HOT 3
- Would you say that the time and effort you spent to create and maintain your Zettelkasten(personal Wiki) was worth the effort? HOT 1
- Questions on second brain platforms HOT 1
- What do you think of Eindhoven? HOT 3
- Want to add more Political Science knowledge in learn-anything.xyz
- Spacebar mapping for palettes? HOT 1
- Thank you for the love for Graphic Walker HOT 1
- Great site HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ama.