-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8dbe065
Showing
6 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
node_modules |
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,25 @@ | ||
# hain-plugin-meme | ||
|
||
[![npm](https://img.shields.io/npm/dt/hain-plugin-meme.svg)](https://www.npmjs.com/package/hain-plugin-meme | ||
) [![npm](https://img.shields.io/npm/dm/hain-plugin-meme.svg)](https://www.npmjs.com/package/hain-plugin-meme | ||
) [![GitHub release](https://img.shields.io/github/release/metrakit/hain-plugin-meme.svg)](https://www.npmjs.com/package/hain-plugin-meme) | ||
|
||
A plugin for generate fastly a meme in the [Hain](https://github.com/appetizermonster/hain) app (Alfred clone for Windows). | ||
This plugin use the [Memegen API](http://memegen.link). | ||
|
||
## Install | ||
|
||
Type this command in the Hain input : | ||
``` | ||
/hpm install meme | ||
``` | ||
|
||
## Usage | ||
|
||
``` | ||
/meme I'm awesome / Yeah ! / | ||
``` | ||
|
||
### Credit | ||
|
||
Thanks to [Memegen](http://memegen.link/) |
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,70 @@ | ||
'use strict'; | ||
|
||
const got = require('got'); | ||
const _ = require('lodash'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const ncp = require("copy-paste"); | ||
|
||
const tplUrl = 'http://memegen.link/templates/'; | ||
|
||
module.exports = (context) => { | ||
const shell = context.shell; | ||
const logger = context.logger; | ||
|
||
let html = []; | ||
let tpls = []; | ||
|
||
function startup() { | ||
html = fs.readFileSync(path.join(__dirname, 'preview.html'), 'utf8'); | ||
got(tplUrl).then(response => { | ||
tpls = JSON.parse(response.body); | ||
}); | ||
} | ||
|
||
function search(query, res) { | ||
const query_trim = query.trim(); | ||
const query_parts = _.split(query_trim, '/', 3); | ||
|
||
logger.log(query_parts); | ||
logger.log(query_parts.length); | ||
|
||
res.add({ | ||
id: `help`, | ||
payload: 'help', | ||
title: 'How to', | ||
desc: 'For generate a meme type : /meme Example / awesome meme /' | ||
}); | ||
|
||
if (query_parts.length === 3) { | ||
return _.forEach(tpls, (url, name) => { | ||
url = _.replace(url, 'templates/', ''); | ||
url += '/' + encodeURIComponent(query_parts[0]) + '/' + encodeURIComponent(query_parts[1]) + '.jpg'; | ||
res.add({ | ||
id: url, | ||
payload: 'open', | ||
title: name, | ||
desc: 'Click for copy the meme to your clipboard', | ||
icon: '#fa fa-file-image-o', | ||
preview: true | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
function execute(url, payload) { | ||
if (payload !== 'open') | ||
return; | ||
ncp.copy(url, function() { | ||
context.toast.enqueue('Pasted to clipboard !'); | ||
}) | ||
} | ||
|
||
function renderPreview(url, payload, render) { | ||
var preview = html.replace('%picture%', url); | ||
preview = preview.replace('%url%', url); | ||
render(preview); | ||
} | ||
|
||
return { startup, search, execute, renderPreview }; | ||
}; |
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,31 @@ | ||
{ | ||
"name": "hain-plugin-meme", | ||
"version": "0.0.1", | ||
"description": "hain plugin to search a meme on giphy.com", | ||
"main": "index.js", | ||
"scripts": {}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/metrakit/hain-plugin-meme.git" | ||
}, | ||
"author": "Jordane JOUFFROY", | ||
"license": "MIT", | ||
"keywords": [ | ||
"hain0" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/metrakit/hain-plugin-meme/issues" | ||
}, | ||
"homepage": "https://github.com/metrakit/hain-plugin-meme", | ||
"dependencies": { | ||
"got": "^6.2.0", | ||
"lodash": "^4.6.1", | ||
"copy-paste": "^1.1.4" | ||
}, | ||
"hain": { | ||
"prefix": "/meme", | ||
"usage": "/meme an awesome meme", | ||
"icon": "/logo.png", | ||
"redirect": "/meme " | ||
} | ||
} |
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,26 @@ | ||
<!doctype html> | ||
<head> | ||
<style type="text/css"> | ||
img { | ||
max-width: 100%; | ||
} | ||
input { | ||
height: 28px; | ||
border-radius: 5px; | ||
border: solid 1px lightgray; | ||
padding-left: 2%; | ||
padding-right: 2%; | ||
width: 96%; | ||
outline: 0; | ||
} | ||
.img-block { | ||
text-align: center; | ||
} | ||
</style> | ||
<body> | ||
<div class="img-block"> | ||
<img src="%picture%"> | ||
</div> | ||
<input type="text" value="%url%"> | ||
</body> | ||
</html> |