Skip to content

Instantly share code, notes, and snippets.

@alpgul
alpgul / content.js
Last active October 30, 2018 09:13
JavaScript Can Change HTML Content
document.getElementById("demo").innerHTML = "Hello JavaScript!"
document.getElementById('demo').innerHTML = 'Hello JavaScript';
//---------------
document.getElementById("demo").style.fontSize = "35px";
//or
document.getElementById('demo').style.fontSize = '35px';
//-----------
document.getElementById("demo").style.display = "none";
//or
document.getElementById('demo').style.display = 'none';
@alpgul
alpgul / js.html
Created October 30, 2018 09:18
JavaScript Where To
<--The <script> Tag-->
<script>
document.getElementById("demo").innerHTML = "My First JavaScript";
</script>
<--JavaScript in <head>-->
<head>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed.";
@alpgul
alpgul / output.js
Created October 30, 2018 09:22
JavaScript Output
//Using innerHTML
document.getElementById("demo").innerHTML = 5 + 6;
//Using document.write()
document.write(5 + 6);
//Bir HTML belgesi yüklendikten sonra document.write () kullanmak, mevcut tüm HTML’leri siler:
//Using window.alert()
window.alert(5 + 6);
@alpgul
alpgul / Statements.js
Created October 30, 2018 09:56
JavaScript Statements
//Semicolons ;
var a, b, c; // Declare 3 variables
a = 5; // Assign the value 5 to a
b = 6; // Assign the value 6 to b
c = a + b; // Assign the sum of a and b to c
// one line
a = 5; b = 6; c = a + b;
//JavaScript White Space
var person = "Hege";
@alpgul
alpgul / Syntax.js
Created October 30, 2018 10:03
JavaScript Syntax
//JavaScript Values
var x, y; // How to declare variables
x = 5; y = 6; // How to assign values
z = x + y; // How to compute values
//JavaScript Literals
Numbers are written with or without decimals:
10.50
1001
WebSocket.prototype._send = WebSocket.prototype.send;
WebSocket.prototype.send = function (data) {
console.log("\u2192 " + data);
this._send(data);
this.addEventListener('message', function (msg) {
console.log('\u2190 ' + msg.data);
}, false);
this.send = function (data) {
this._send(data);
console.log("\u2192 " + data);
@alpgul
alpgul / select_tags_with_text.js
Created June 8, 2019 06:07
How to select all tags with specific text content in Javascript?
function contains(selector, text) {
var elements = document.querySelectorAll(selector);
return Array.prototype.filter.call(elements, function(element){
return RegExp(text).test(element.textContent);
});
}
@alpgul
alpgul / extension.js
Last active July 22, 2021 12:41
Tampermonkey extension.js GM_screenShot
! function ( e ) {
function t( r ) {
if ( n[ r ] ) return n[ r ].exports;
var i = n[ r ] = {
i: r,
l: !1,
exports: {}
};
return e[ r ].call( i.exports, i, i.exports, t ), i.l = !0, i.exports
}
@alpgul
alpgul / content.js
Last active July 22, 2021 12:39
Tampermonkey content.js GM_screenShot
! function ( e ) {
function t( o ) {
if ( n[ o ] ) return n[ o ].exports;
var s = n[ o ] = {
i: o,
l: !1,
exports: {}
};
return e[ o ].call( s.exports, s, s.exports, t ), s.l = !0, s.exports
}