javascript javascipt中的排列

这是用于置换javascript中所有元素的算法

permutation.js
var permArr = [],
  usedChars = [];

function permute(input) {
    var i, ch;
    for (i = 0; i < input.length; i++) {
        ch = input.splice(i, 1)[0];
        usedChars.push(ch);
        if (input.length == 0) {
            permArr.push(usedChars.slice());
        }
            permute(input);
            input.splice(i, 0, ch);
            usedChars.pop();
        }
        return permArr
    };
}

javascript 铬 - 扩展 - 清单

extension--manifest

// manifest.json
{
"name": "",
"version": "0.1",
"description": "",
"manifest_version" : 2, 
"content_scripts" : [
    {
      "matches" : ["*://*"],
      "js" : ["myscripts.js"],
	  // "run_at":"document_end"
    }
  ],


}

javascript chrome - 加载前编辑dom

edit dom before load
editElements('');

function editElements(selector) {
    // in case the content script was injected after the page is partially loaded
    doDelete(document.querySelectorAll(selector));
    var ii = 1

    var mo = new MutationObserver(process);
    mo.observe(document, {subtree:true, childList:true});
    document.addEventListener('DOMContentLoaded', function() { mo.disconnect() });

    function process(mutations) {
        for (var i = 0; i < mutations.length; i++) {
            var nodes = mutations[i].addedNodes;
            for (var j = 0; j < nodes.length; j++) {
                var n = nodes[j];
                if (n.nodeType != 1) // only process Node.ELEMENT_NODE
                    continue;
                doDelete(n.matches(selector) ? [n] : n.querySelectorAll(selector));
            }
        }
    }
    function doDelete(nodes) {
        [].forEach.call(nodes, function(node) {
            if (ii == 1){
                // node.remove();
                ii += 1
            }
             });
    }
}

javascript ハンバーガーメニュー:全画面,横からスライド

(参考サイト)<br/> https://www.webopixel.net/javascript/1483.html

index.html
<div class="sp_header">
            <p class="sp_header_logo"><img src="images/logo_header.png" alt="文花堂"></p>
            <p><span data-action="call" data-tel="0667280087"><span class="fas fa-phone fa-flip-horizontal"></span></p>
            <div id="nav-toggle">
                <div>
                    <span></span>
                    <span></span>
                    <span></span>
                </div>
            </div>
            <div id="gloval-nav">
                <nav>
                    <ul class="flex_box flex_between flex_wrap">
                        <li><a href="../store/">店舗案内</a></li>
                        <li><a href="../celebration/">スタンド花(生花)</a></li>
                        <li><a href="../celebration/hanawa.html">花輪(造花)</a></li>
                        <li><a href="../celebration/kochoran.html">胡蝶蘭</a></li>
                        <li><a href="../gift/">フラワーアレンジ</a></li>
                        <li><a href="../celebration/event.html">各種イベント</a></li>
                        <li><a href="../gift/hanataba.html">花束</a></li>
                        <li><a href="../gift/kanyo.html">観葉植物</a></li>
                        <li><a href="../gift/bridal.html">ブライダル</a></li>
                        <li><a href="../gift/osonae.html">お供花</a></li>
                        <li><a href="../contact/index.php">お問い合せ</a></li>
                        <li><a href="../link/">リンク</a></li>
                        <li><a href="../privacy/">プライバシーポリシー</a></li>
                    </ul>
                </nav>
            </div>
        </div>
style.css
/*---------- ヘッダー ----------*/
#header {
    padding: 0;
}

.pc_header {
    display: none
}

.sp_header {
    width: 100%;
    position: fixed;
    top: 0;
    background: #623e10;
    padding: 15px;
}

.sp_header_logo img {
    width: 40%;
}

.sp_header .fa-phone {
    color: #ffffff;
    font-size: 2.7rem;
    position: absolute;
    top: 25px;
    right: 80px;
}

/*---------- ハンバーガーメニュー ----------*/
#nav-toggle {
    position: fixed;
    top: 25px;
    right: 25px;
    height: 32px;
    cursor: pointer;
}
#nav-toggle > div {
    position: relative;
    width: 36px;
}
#nav-toggle span {
    width: 100%;
    height: 2px;
    left: 0;
    display: block;
    background: #ffffff;
    position: absolute;
    transition: top .5s ease, -webkit-transform .6s ease-in-out;
    transition: transform .6s ease-in-out, top .5s ease;
    transition: transform .6s ease-in-out, top .5s ease, -webkit-transform .6s ease-in-out;
}
#nav-toggle span:nth-child(1) {
    top: 4px;
}
#nav-toggle span:nth-child(2) {
    top: 14px;
}
#nav-toggle span:nth-child(3) {
    top: 23px;
}
#nav-toggle:hover span:nth-child(1) {
    top: 4px;
}
#nav-toggle:hover span:nth-child(3) {
    top: 23px;
}
.open #nav-toggle span {
    background: #fff;
}
.open #nav-toggle span:nth-child(1) {
    top: 15px;
    -webkit-transform: rotate(45deg);
    transform: rotate(45deg);
}
.open #nav-toggle span:nth-child(2) {
    top: 15px;
    width: 0;
    left: 50%;
}
.open #nav-toggle span:nth-child(3) {
    top: 15px;
    -webkit-transform: rotate(-45deg);
    transform: rotate(-45deg);
}

/* z-index */
#nav-toggle {
    z-index: 1000;
}

#container {
    z-index: 900;
}

#gloval-nav {
    background: rgba(98,62,16,0.9);
    color: #fff;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 990;
    display: flex;
    visibility: hidden;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 29px;
    opacity: 0;
    transition: opacity .6s ease, visibility .6s ease;
    padding: 30px;
}

#gloval-nav a {
    display: block;
    color: #fff;
    text-decoration: none;
    padding: 10px 0 10px 20px;
    transition: color .6s ease;
}
#gloval-nav a:hover {
    color: #666;
}
#gloval-nav ul {
    list-style: none;
}
#gloval-nav ul li {
    font-size: 1.6rem;
    width: 48%;
    position: relative;
    opacity: 0;
    -webkit-transform: translateX(200px);
    transform: translateX(100px);
    transition: opacity .2s ease, -webkit-transform .6s ease;
    transition: transform .6s ease, opacity .2s ease;
    transition: transform .6s ease, opacity .2s ease, -webkit-transform .6s ease;
}
#gloval-nav ul li:nth-child(odd) {
    transition-delay: .15s;
}
#gloval-nav ul li:nth-child(even) {
    transition-delay: .3s;
}
#gloval-nav ul li:before {
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    content:"\f054";
    color: #ffffff;
    position: absolute;
    top: 10px;
    left: 0;
}

/* open */
.open {
    overflow: hidden;
}
.open #gloval-nav {
    visibility: visible;
    opacity: 1;
}
.open #gloval-nav li {
    opacity: 1;
    -webkit-transform: translateX(0);
    transform: translateX(0);
    transition: opacity .9s ease, -webkit-transform 1s ease;
    transition: transform 1s ease, opacity .9s ease;
    transition: transform 1s ease, opacity .9s ease, -webkit-transform 1s ease;
}
common.js
(function ($) {
   $(function () {
      $('#nav-toggle').on('click', function () {
         $('body').toggleClass('open');
      });
   });
})(jQuery);

javascript 脚本方法

A.md
# postman里的script方法
loopValue.js

loopValue('loop_car_no', ['粤E57376', '粤DHC782'])

/**
 * 循环输出数组
 * 
 * @param string key 需要设置的变量
 * @param array arr 循环的数组
 */ 
function loopValue(key, arr){
    var currentValue = pm.globals.get(key);
    
    if (!currentValue){
        pm.globals.set(key, arr.shift());
        return;
    }
    
    for(i = 0; i < arr.length; i++){
        if (arr[i] == currentValue){
            pm.globals.set(key, arr[i+1 >= arr.length ? 0 : i+1]);
            return;
        }
    }
    
}

javascript Exportar Datatable是一个PDF格式

jspdf.js
/**
 * Librería requerida: npm install pdfmake
 * */
 
import pdfMake from 'pdfmake/build/pdfmake';
import pdfFonts from 'pdfmake/build/vfs_fonts';
pdfMake.vfs = pdfFonts.pdfMake.vfs;

/**
 * @param data Object[] Ej. [{ nombre: 'Marcelo', apellido: 'Forclaz' }]
 * @param columns Object[] Ej. [{ label: 'Nombre', key: 'nombre' }]
 **/
 
export const pdf = (data, columns) => {
  const cols = [
    columns.map(item => ({
      text: item.label,
      style: 'tableHeader'
    }))
  ];
  const rows = data.reduce((acc, item) => {
    const row = [];
    columns.forEach(col => {
      row.push({ text: item[col.key], fontSize: 8 });
    });
    acc.push(row);
    return acc;
  }, []);
  const dd = {
    content: [
      {
        table: {
          fontSize: 8,
          body: cols.concat(rows)
        }
      }
    ],
    styles: {
        tableHeader: {
            fillColor: '#212121',
            fontSize: 8,
            color: '#ffffff'
        }
    }
  };
  pdfMake.createPdf(dd).open();
};

javascript FV :: redirect点击领导者图片

FV :: redirect点击领导者图片

gistfile1.js

if ( ! jQuery("body").hasClass("home") ) {
  jQuery(".fv-leaders img").on("click", function(e) {
    e.preventDefault();
    window.location.href = "YOUR URL";
  });
}

javascript 滚动到网址哈希

srollToUrlHash.js
    window.addEventListener("load", function() {
        var offset = -100;
        if(window.location.hash != null && window.location.hash.length > 0) {
            $(document).scrollTop($(window.location.hash).offset().top - offset);
        }
    });

javascript 重量转换器

weight converter

<!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">
    <meta http-equiv="X-UA-Compatible"
    content="ie=edge">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" 
            integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" 
            crossorigin="anonymous">
    <style>
        body{
  margin-top:70px;
  background:#333;
  color:#fff;
}
    </style>
 <title> Convertidor de ganancias  </title>
 </head>

<div class="container">
    <div class="row">
      <div class="col-md-6 offset-md-3">
        <h1 class="display-4 text-center mb-3">Convertidor de ganancias</h1>
        <form>
          <div class="form-group">
            <input id="lbsInput" type="number" class="form-control form-control-lg" placeholder="Pesos colombianos">
          </div>
        </form>
        <div id="output">
          <div class="card bg-primary mb-2">
            <div class="card-body">
              <h4>Crepes:</h4>
              <div id="gramsOutput"></div>
            </div>
          </div>
  
          <div class="card bg-success mb-2">
            <div class="card-body">
              <h4>Tratamiento:</h4>
              <div id="kgOutput"></div>
            </div>
          </div>
  
          <div class="card bg-danger mb-2">
            <div class="card-body">
              <h4>Eventos:</h4>
              <div id="ozOutput"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <script>
  document.getElementById("output").style.visibility = "hidden";
document.getElementById("lbsInput").addEventListener("input", function(e) {
  document.getElementById("output").style.visibility = "visible";
  let lbs = e.target.value;
  document.getElementById("gramsOutput").innerHTML = (lbs / 3000).toFixed(2);
  document.getElementById("kgOutput").innerHTML = (lbs / 100000).toFixed(2);
  document.getElementById("ozOutput").innerHTML = (lbs / 1000000).toFixed(2);
});

  </script>

javascript 排列

array.js
const companies= [
    {name: "Company One", category: "Finance", start: 1981, end: 2004},
    {name: "Company Two", category: "Retail", start: 1992, end: 2008},
    {name: "Company Three", category: "Auto", start: 1999, end: 2007},
    {name: "Company Four", category: "Retail", start: 1989, end: 2010},
    {name: "Company Five", category: "Technology", start: 2009, end: 2014},
    {name: "Company Six", category: "Finance", start: 1987, end: 2010},
    {name: "Company Seven", category: "Auto", start: 1986, end: 1996},
    {name: "Company Eight", category: "Technology", start: 2011, end: 2016},
    {name: "Company Nine", category: "Retail", start: 1981, end: 1989}
  ];
  
  const ages = [33, 12, 20, 16, 5, 54, 21, 44, 61, 13, 15, 45, 25, 64, 32];
  
  // for(let i = 0; i < companies.length; i++) {
  //   console.log(companies[i]);
  // }
  
  // forEach
  
  // companies.forEach(function(company) {
  //   console.log(company.name);
  // });
  
  // filter
  
  // Get 21 and older
  
  // let canDrink = [];
  // for(let i = 0; i < ages.length; i++) {
  //   if(ages[i] >= 21) {
  //     canDrink.push(ages[i]);
  //   }
  // }
  
  // const canDrink = ages.filter(function(age) {
  //   if(age >= 21) {
  //     return true;
  //   }
  // });
  
  const canDrink = ages.filter(age => age >= 21);
  
  // Filter retail companies
  
  // const retailCompanies = companies.filter(function(company) {
  //   if(company.category === 'Retail') {
  //     return true;
  //   }
  // });
  
  const retailCompanies = companies.filter(company => company.category === 'Retail');
  
  // Get 80s companies
  
  const eightiesCompanies = companies.filter(company => (company.start >= 1980 && company.start < 1990));
  
  // Get companies that lasted 10 years or more
  
  const lastedTenYears = companies.filter(company => (company.end - company.start >= 10));
  
  // map
  
  // Create array of company names
  // const companyNames = companies.map(function(company) {
  //   return company.name;
  // });
  
  // const testMap = companies.map(function(company) {
  //   return `${company.name} [${company.start} - ${company.end}]`;
  // });
  
  // const testMap = companies.map(company => `${company.name} [${company.start} - ${company.end}]`);
  
  // const ageMap = ages
  //   .map(age => Math.sqrt(age))
  //   .map(age => age * 2);
  
  
  
  // sort
  
  // Sort companies by start year
  
  // const sortedCompanies  = companies.sort(function(c1, c2) {
  //   if(c1.start > c2.start) {
  //     return 1;
  //   } else {
  //     return -1;
  //   }
  // });
  
  // const sortedCompanies = companies.sort((a, b) => (a.start > b.start ? 1 : -1));
  
  // Sort ages
  // const sortAges = ages.sort((a, b) => a - b);
  
  // console.log(sortAges);
  
  
  // reduce
  
  // let ageSum = 0;
  // for(let i = 0; i < ages.length; i++) {
  //   ageSum += ages[i];
  // }
  
  // const ageSum = ages.reduce(function(total, age) {
  //   return total + age;
  // }, 0);
  
  // const ageSum = ages.reduce((total, age) => total + age, 0);
  
  // Get total years for all companies
  
  // const totalYears = companies.reduce(function(total, company) {
  //   return total + (company.end - company.start);
  // }, 0);
  
  const totalYears = companies.reduce((total, company) => total + (company.end - company.start), 0);
  
  // Combine Methods
  
  const combined = ages
    .map(age => age * 2)
    .filter(age => age >= 40)
    .sort((a, b) => a - b)
    .reduce((a, b) => a + b, 0);
  
  console.log(combined);