-
Notifications
You must be signed in to change notification settings - Fork 0
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 8a47784
Showing
7 changed files
with
141 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,2 @@ | ||
/node_modules/ | ||
package-lock.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,27 @@ | ||
{ | ||
"name": "social-media", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "npx webpack --config webpack.config.js --watch", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Project-fahrul/Social-Media-Generator.git" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/Project-fahrul/Social-Media-Generator/issues" | ||
}, | ||
"homepage": "https://github.com/Project-fahrul/Social-Media-Generator#readme", | ||
"devDependencies": { | ||
"@babel/core": "^7.18.5", | ||
"@babel/preset-env": "^7.18.2", | ||
"babel-loader": "^8.2.5", | ||
"webpack": "^5.73.0", | ||
"webpack-cli": "^4.10.0" | ||
} | ||
} |
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,3 @@ | ||
# Social Media Generator | ||
|
||
Social Media Generator is a javascript library for sharing links of web page to social media |
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,55 @@ | ||
class SocialMedia { | ||
link = null | ||
socialLink = { | ||
wa: { | ||
selector: "a[wa-social]", | ||
link: "https://api.whatsapp.com/send?text=1%", | ||
attribute: { | ||
"data-action": "share/whatsapp/share", | ||
} | ||
}, | ||
fb: { | ||
selector: "a[fb-social]", | ||
link: "https://www.facebook.com/sharer.php?u=1%", | ||
}, | ||
twitter:{ | ||
selector: 'a[twitter-social]', | ||
link: "https://twitter.com/intent/tweet?url=1%&text=2%", | ||
args: [document.title] | ||
}, | ||
linkin: { | ||
selector: 'a[linkin-social]', | ||
link: "https://www.linkedin.com/shareArticle?mini=true&url=1%", | ||
} | ||
} | ||
|
||
constructor() { | ||
this.link = window.location.href | ||
Object.keys(this.socialLink).forEach(e => { | ||
this.constructLink(this.socialLink[e]) | ||
}) | ||
} | ||
|
||
constructLink = (arg) => { | ||
let el = document.querySelectorAll(arg.selector) | ||
let link = arg.link.replace("1%", this.link); | ||
if(arg.args){ | ||
arg.args.forEach((e,i)=>{ | ||
link = link.replace((i+2)+"%", e) | ||
}) | ||
} | ||
//set link | ||
Array.prototype.forEach.call(el, (e) => { | ||
e.setAttribute("href", link) | ||
//set attribute | ||
if (arg.attribute) | ||
Object.keys(arg.attribute).forEach(att => { | ||
e.setAttribute(att, arg.attribute[att]) | ||
}) | ||
|
||
}) | ||
} | ||
} | ||
|
||
|
||
new SocialMedia() |
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,29 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
<style> | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<ul> | ||
<li><a href="/" wa-social>Whattapp</a></li> | ||
<li><a href="/" fb-social>Facebook</a></li> | ||
<li><a href="/" twitter-social>Twitter</a></li> | ||
<li><a href="/" linkin-social>Linkin</a></li> | ||
</ul> | ||
|
||
<script src="../dist/main.js"></script> | ||
</body> | ||
|
||
</html> |
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,24 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
mode: "production", | ||
entry: './social-media.js', | ||
output: { | ||
filename: 'main.js', | ||
path: path.resolve(__dirname, 'dist'), | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.m?js$/, | ||
exclude: /(node_modules|bower_components)/, | ||
use: { | ||
loader: 'babel-loader', | ||
options: { | ||
presets: ['@babel/preset-env'] | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}; |