├── .gitignore ├── .DS_Store ├── yarn.lock ├── README.md ├── plugin.json ├── static └── lib │ └── main.js ├── library.js ├── LICENSE └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netdata/nodebb-plugin-twitter-netdata/master/.DS_Store -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NodeBB Twitter Plugin 2 | 3 | This is a Netdata fork of the NodeBB plugin found here: https://github.com/NodeBB-Community/nodebb-plugin-twitter 4 | -------------------------------------------------------------------------------- /plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nodebb-plugin-twitter", 3 | "name": "NodeBB Twitter Embed Plugin", 4 | "description": "NodeBB Plugin that allows users to embed tweets inline in their posts.", 5 | "url": "https://github.com/dovydaskukalis/nodebb-plugin-twitter", 6 | "library": "./library.js", 7 | "hooks": [ 8 | { "hook": "filter:header.build", "method": "init.global.addNavigation" }, 9 | { "hook": "filter:parse.post", "method": "parse", "priority": 6 } 10 | ], 11 | "scripts": [ 12 | "static/lib/main.js" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /static/lib/main.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* globals document, $ */ 4 | 5 | $(document).ready(function () { 6 | // Inject twitter widget into footer 7 | var scriptEl = document.createElement('script'); 8 | scriptEl.async = 'async'; 9 | scriptEl.src = '//platform.twitter.com/widgets.js'; 10 | scriptEl.charset = 'utf-8'; 11 | 12 | document.head.appendChild(scriptEl); 13 | 14 | function enhanceEmbed() { 15 | var target = $('ul[component="topic"]').get(0); 16 | twttr.widgets.load(target); 17 | } 18 | 19 | $(window).on('action:posts.loaded action:topic.loaded', function () { 20 | setTimeout(enhanceEmbed, window.twttr ? 0 : 1000); 21 | }); 22 | }); -------------------------------------------------------------------------------- /library.js: -------------------------------------------------------------------------------- 1 | (function(module) { 2 | "use strict"; 3 | 4 | var Twitter = {}, 5 | embed = '
';
6 |
7 | Twitter.parse = function(data, callback) {
8 | var regularUrl = /.+?<\/a>/g
9 | var postContent = data && data.postData && data.postData.content;
10 |
11 | if (postContent && postContent.match(regularUrl)) {
12 | data.postData.content = postContent.replace(regularUrl, embed);
13 | }
14 | callback(null, data);
15 | };
16 |
17 | module.exports = Twitter;
18 | }(module));
19 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014, Dovydas